javascript - NodeJS package dependencies -
i have defined npm package following dependencies:
"dependencies": { "kwire": "0.0.1" }
i create new project folder node_modules
folder in root , package.json
, , run npm install --save my-package
.
i end my-package
being placed in node_modules
, , dependencies being placed in inner node_modules
folder, within my-package
folder.
this seems normal.
when fire node.js repl my-project
folder , write:
var m = require('my-package');
it results in error kwire
not defined.
it falling on over line inside my-package
:
require('kwire');
what need ensure my-package
can see kwire
?
i suggest using "files": []
inside package.json
file. typical workflow structure package.json
:
"dependencies": { "package1": "latest", "package2": "latest" ... }, "files": [ "index.js", "lib/" ]
inside index.js
prefer passing dependencies lib/
folder as:
'use strict'; module.exports = require('./lib/bootstrap');
and /lib/bootstrap.js can start injecting module as:
var test = require('package1');
or local dependency as:
var router = require('./router');
here useful gist explaining module dependencies.
Comments
Post a Comment