NPM cheat sheet

Shortcuts

Basics

Create a project

$ npm init

Install dependencies

$ npm install

Add package

$ npm install express # installs express

Add package globally (don’t use it)

$ sudo npm install -g express

Add package (development env only)

$ npm install eslint --save-dev # installs eslint

Run linting

$ npm run lint

Generate an express app skeleton

$ npm install express-generator -g
$ express helloworld
$ code helloworld && npm install

Start a green field express project

$ npm init
$ npm install express --save
$ npm install babel-cli --save # compile ES6 to ES5
$ npm install babel-preset-es2015 --save # compile ES6 to ES5
$ echo '{ "presets": ["es2015"] }' >> .babelrc
$ npm install nodemon --save-dev # for live reload
$ npm install --save body-parser # to parse request body

And then add the below line to package.json under script section,

"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1",
  "start": "nodemon app.js --exec babel-node --"
}

Lastly, run the app npm run start

Scaffold express app with express-generator

$ npx express-generator my_new_fancy_app
$ express my_new_fancy_app

Remove a dependency

$ npm uninstall jade
$ npm prune