Comments (3)
@yolapop Hi, thanks for the great question.
Isn't it needed to add ./ in require to find local modules?
Yes, you are absolutely correct here. Now that you point that out, I think I should probably update that section as it is currently inaccurate.
Node.js will perform a hierarchical directory search for "node_modules" and "utils" in the following ways:
./node_modules/utils.js
./node_modules/utils/index.js
./node_modules/utils/package.json
I don't think this is technically accurate either... the directory search would look like this instead:
- node would check for existence of
./node_modules/utils/package.json
- if it does not exist, it will try
../node_modules/utils/package.json
- if that does not exist, it will try
.../node_modules/utils/package.json
etc until it reaches/
- when it finds some folder called
utils
with apackage.json
in it inside of anode_modules
it will read thepackage.json
and check and see if amain
property is set. for example, you could set yourmain
to be calledutils.js
. otherwise ifmain
is not specified it will default to looking forindex.js
- finally, now that it knows the folder of the
utils
module and the name of the main entry file, it willrequire
the main entry file
hope this helps!
from art-of-node.
@yolapop also I can highly recommend this nodeschool workshop https://github.com/npm/how-to-npm
from art-of-node.
Thanks for the answer and recommendation!
On Sun, Mar 22, 2015, 11:41 PM Max Ogden [email protected] wrote:
@yolapop https://github.com/yolapop also I can highly recommend this
nodeschool workshop https://github.com/npm/how-to-npm—
Reply to this email directly or view it on GitHub
#51 (comment).
from art-of-node.
Related Issues (20)
- Time Server Problem HOT 1
- Sorry Again Wrong repo
- Remove the laser from the hard drive HOT 3
- Can we simplify the callbacks pseudocode please? HOT 7
- I get this error after running npm install learnyounode -g. Ubuntu 14.04 HOT 2
- parseInt mystery HOT 2
- Why not use GitHub pages to host this doc? HOT 5
- CoolBear example throws a error in RequireBin HOT 3
- Link mentioned in the doc is not working/changed
- Callbacks pseudocode missing passed arguments HOT 1
- README file contains a broken link to a git/github resource HOT 2
- Can I be an admin on this repo? HOT 1
- Promises add complexity? HOT 5
- RequireBin example error HOT 2
- Wrong number?
- asynch file IO how complex it can be? HOT 3
- RequireBin Example Doesn't Work on Chromium
- Error in solution of My First Async IO lesson HOT 1
- Requirebin link domain leads to gambling website
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from art-of-node.