A Beginner’s Guide to npm, the Node Package Manager
Code snippet
$ npm list -g --depth=0/home/sitepoint/.node_modules_global/lib├── npm@6.9.0└── uglify-js@3.4.9That’s better—just the packages we’ve installed along with their version numbers.
Any packages installed globally will become available from the command line. For example, here’s how you’d use the Uglify package to minify example.js into example.min.js:
Code snippet
$ uglifyjs example.js -o example.min.jsInstalling Packages in Local Mode
When you install packages locally, you normally do so using a package.json file. Let’s go ahead and create one:
Code snippet
$ npm initpackage name: (project)version: (1.0.0)description: Demo of package.jsonentry point: (index.js)test command:git repository:keywords:author:license: (ISC)Press Enter to accept the defaults, then type yes to confirm. This will create a package.json file at the root of the project:
Code snippet
{ "name": "project", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC"}