Move local paths for require () in node.js

In RequireJS, I can reassign the paths using the config file , for example:

require.config({
    paths: {
        foo: 'lib/foo/foo'
    }
})

Then I can use foo like this:

require(['foo'], function(foo) {...})

In node.js, I may also need local files, for example:

var foo = require('../lib/foo/foo.js')

(In this example foo.js, this is a file that I wrote that is not accessible via npm.)

Is it possible to reassign 'foo'to '/lib/foo/foo.js'relatively some base directory in node.js, so I don't need to use relative paths?

+2
source share
1 answer

You cannot “reassign” things to Node - at least not from the very beginning, perhaps there are packages for this purpose.

node_modules .
bundledDependencies package.json. . .

+1

All Articles