For example if your project had this package.json file, running npm -install would create a node_modules sub-directory and install express and mocha into it:
{
"name": "awesome-app",
"version": "0.0.1",
"dependencies": {
"express": "3.0.0rc3"
,"mocha": "latest"
}
}
It's also fairly common to install some modules globally, using npm -g, if they provide command-line utilities. For example, if you wanted to have jslint available to all users on your system, you'd do this:
sudo npm -g install jslint
which would place this in /usr/local/bin/jslint.
If you specify a dependency in your package.json file, and that module includes an executable -- like jslint, for example, or mocha -- then npm install will automatically place those executables in your project's node_modules/.bin directory. To make use of these, add this prefix to your $PATH in your ~/.bashrc file:
export PATH=./node_modules/.bin:$PATH
This allows each one of your NodeJS projects to independently specify, install and use not only packages that are required in your JavaScript code, but also the command-line tools you need for testing, linting, or otherwise building your app.
No comments:
Post a Comment