Node.js is a JavaScript runtime built on Chrome’s V8 JavaScript engine.
Installation Link to heading
Here you can find Node.js Binary Distributions with all versions.
Project settings Link to heading
Custom registry Link to heading
1npm config set registry 'http://servername:port'
Disable SSL verification for your private repository Link to heading
1npm config set strict-ssl false --userconfig ./.npmrc
Set predefined data for node projects Link to heading
1npm config set init.author.name "John Smith"
2npm config set init.author.email "some@server.com"
3npm config set init.author.url "https://someserver.com"
4npm config set init.license "MIT"
5npm config set init.version "0.0.1"
These values will be automatically substituted into the new project by npm init -y
command.
NPM commands Link to heading
Aliases Link to heading
Command | Description |
---|---|
npm i <package> |
install local package |
npm i -g <package> |
install global package |
npm un <package> |
uninstall local package |
npm up |
npm update packages |
npm t |
run tests |
npm ls |
list installed modules |
npm ll or npm la |
print additional package information while listing modules |
Show information/dependencies about a package Link to heading
1npm view express dependencies
2npm ls express
3npm ll express
4# Find dependencies inside your node_modules
5find ./node_modules/ -name package.json | xargs grep <the_package_name>
Update all the Node dependencies to their latest version Link to heading
To update to a new major version all the packages, install the npm-check-updates package globally:
1npm install -g npm-check-updates
To see all ‘old’ packages:
1npm outdated
To update all versions inside the package.json:
1ncu -u
This will upgrade all the version hints in the package.json file, to dependencies and devDependencies, so npm can install the new major version.
Now you can create a new one or update node_modules:
1npm install
2# or
3npm update
Popular packages Link to heading
dotenv Link to heading
Load .env values into the system environment
1# option 1: (doesn't work if you have spaces in the values)
2export $(grep -i "^[A-Z]" "./.env" | tr '\r\n' '\n' | xargs)
3# option 2: bash version
4set -a # automatically export all variables
5. .env
6# or
7source .env
8set +a
Use dotenv from the scripts only (without load in the code)
1 "scripts": {
2 "start:dev": "node -r dotenv/config src/server.js"
3 }
eslint Link to heading
Add eslint + airbnb to your project:
- Add packages:
npm i --save-dev eslint eslint-config-airbnb-base eslint-plugin-import
- Create .eslintrc.js: module.exports = { “extends”: “airbnb-base” };
- In VSCode install the ESLint extension
- Add script into the packaje.json:
"lint": "eslint ./"
Sample eslint config file: .eslintrc.js
1module.exports = {
2 extends: ['airbnb-base'],
3 root: true,
4 env: {
5 node: true,
6 es6: true,
7 jest: true,
8 },
9 plugins: [],
10 rules: {
11 'indent': ['error', 2], // all JS world using 2 chars instead of 4 :(
12 'eol-last': ['error', 'always'], // Enforces at least one newline at the end of a file
13 'max-len': ['error', { code: 120, ignoreUrls: true }],
14 'object-curly-spacing': ['error', 'always'],
15 'max-classes-per-file': ['error', 2],
16 'newline-per-chained-call': ['error', { ignoreChainWithDepth: 3 }],
17 'no-multi-spaces': ['error', { ignoreEOLComments: true }],
18 },
19};
Eslint debug:
1DEBUG=eslint:cli-engine npm run lint