alt
alt

Reputation: 13907

NodeJS require module with path

In the bluebird node module, there are two builds, the normal build, and the sync build.

The normal build, which is required by require('bluebird'), and the sync build, which is required by require('bluebird/zalgo'). How is that accomplished? It's a path, but for an nom package?

Upvotes: 2

Views: 802

Answers (1)

Ray Toal
Ray Toal

Reputation: 88378

After you npm install, take a look in your node_modules directory.

You will see that under bluebird there is a zalgo.js which is the file used when doing require('bluebird/zalgo').

That file has just one line

module.exports = require('./js/zalgo/bluebird.js');

and you can find these files under your node_modules/bluebird file tree also.

You can take a look at the node docs to find out exactly how node resolves the arguments to require. Since your path does not start with '.' it will look in node_modules (or in the global location) and find bluebird. Then it will resolve the rest of the path.

There is more to this, of course, and the docs will tell the full story, but this should get you started.

Upvotes: 3

Related Questions