node your-node-file
. To make use of other modules, you will want to write a package.json
file in the root directory of your program. This file is used to define your application, including information such as its name, description, environments it can run under, and any modules it is dependent on. If you decide to publish your program to the world (making it a module others can use) then you will require a package.json
file.package.json
will look like this:If you are writing a program that you never want to be released to the outside world, you will want to add"private": true
as well. This will tell npm to never publish your program even if someone accidentally runsnpm publish
.
npm publish
in your program's directorynpm install <module-name>
, then you can use it in your code by doing var theModule = require('module-name');
npm install -g <module-name>
{ "dependencies": {"some-dependency": "~1.2.3"} }
which will accepted all v1.2 versions of that dependency that are v1.2.3 or higher{ "dependencies": {"some-dependency": "^1.2.3"} }
which will accepted all v1 versions of that dependency that are v1.2.3 or higher"1.2.3"
directly, as it decreases maintenance when new versions come out which are often compatible depending on the module authors practices.>=1
or *
as soon enough, the module will publish a breaking change that will break your app. Hence why semver exists.