Node.js uses the chrome V8 engine to run javascript outside of the browser.
# linux
sudo apt install nodejs -y
# Check installation success
node -v
npm -v
# update npm to latest
npm install npm@latest -gInstall the LTS version from website. Works for updating node too.
Go to a project folder and run npm init. It will ask a few questions and generate a package.json file.
NPM allows to install packages 2 ways.
- Locally: Runs only in the project folder.
npm install modulename. Installs locally in project folder in a folder callednode_modules, and adds it as a dependency intopackage.json's dependencies section. - Globally: Can run anywhere. Mostly in terminal:
npm install -g live-server. In this case,package.jsonwon't get updated.
Notes
- If installing gives admin errors, run as
sudo. npm installinstalls all dependencies frompackage.json.- Dev dependencies are not needed for deployment so they're added to
package.json's dev dependencies.
Scripts:
npm run scriptname will run a bash command as specified in the package.json. eg:
"scripts" : {
"build": "browserify script.js > bundle.js",
"buildtest": "browserify script.js > bundle.js && live-server"
}