Giter VIP home page Giter VIP logo

Comments (3)

max-mapper avatar max-mapper commented on July 26, 2024

@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 a package.json in it inside of a node_modules it will read the package.json and check and see if a main property is set. for example, you could set your main to be called utils.js. otherwise if main is not specified it will default to looking for index.js
  • finally, now that it knows the folder of the utils module and the name of the main entry file, it will require the main entry file

hope this helps!

from art-of-node.

max-mapper avatar max-mapper commented on July 26, 2024

@yolapop also I can highly recommend this nodeschool workshop https://github.com/npm/how-to-npm

from art-of-node.

yolapop avatar yolapop commented on July 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.