My Node.js notes

From Got Opinion Wiki
Jump to navigation Jump to search

Node.js Package Manager (npm)

npm

Initialize an npm project. Within project directory use npm init command. The default command launches a questionnaire. To answer default on all questions use -y argument.

Uninstall global module

npm uninstall -g nodemon

Install local module

npm install nodemon

Install as dev dependency (not installed on production environment)

npm install nodemon --save-dev

Basic stuff

debugger statement and node inspect

chrome:://inspect

Exit Chrome DevTool debugger.

Type restart at console after exiting Chrome DevTool to restart app with same arguments.

Press CTRL+C twice to exit debugger in console.

nodemon

If nodemon installed globally

nodemon <app.name> -e <comma separated list of extensions to monitor>

If nodemon installed locally a script can launch. See scripts key section for details.

package.json info

scripts key

create key value pair where key is name of script and value is script location

Example:

"scripts": {
    "dev": "nodemon src/app.js -e js,hbs"
  }

At node prompt type npm run dev to execute script nodemon src/app.js -e js,hbs

NPM modules

CORS is a node.js package for providing a Connect/Express middleware that can be used to enable CORS with various options.

The official MongoDB driver for Node.js. Provides a high-level API on top of mongodb-core that is meant for end users.

Mongoose provides a straight-forward, schema-based solution to model your application data. It includes built-in type casting, validation, query building, business logic hooks and more, out of the box.

validator is a library of string validators and sanitizers.

Resources

Node.js home

To software notes