🚀 Node.Js Essentials as Backend Runtime Environment
Tags: Node, NVM, NPM, CORS, Express, Nodemon
🎯 Purpose
- Javascript (JS) a programming language initially created to add dynamic & interactive features to static web pages. Build to run in browsers.
- Node.js is a JS runtime built on Chrome’s V8 engine for running JS code server-side.
- NVM (Node Version Manager) allows easy installation, switching, and management of multiple Node.js versions.
🌱 Origin
- Brendan Eich created JavaScript in 1995 for Netscape Communications. The name was probabely a marketing tactic by Netscape to leverage the popularity of the Java, despite the two being unrelated.
- Node.js was created by Ryan Dahl in 2009, named for its modular “nodes” of functionality.
- NVM was created by Tim Caswell in 2010, with the name directly describing its purpose: managing Node versions.
🧠 Essentials
⚙️ Linux Installation
# Install NVM - Use installation guide versions https://github.com/nvm-sh/nvm
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
# Reload shell
exec $SHELL
# Verify NVM version:
nvm -v
# Install Node.js (LTS)
nvm install --lts
# Verify Node & NPM version
node -v
npm -v
🛠 Useful NVM Commands
nvm ls→ List installed Node versionsnvm ls-remote→ List available Node versionsnvm current→ Show active versionnvm use 20→ Switch to Node version 18nvm alias default 22→ Set default Node versionnvm uninstall <version>→ Remove a version- To uninstall NVM & all Node.js versions on Ubuntu (double check and be carefull):
# Remove NVM directory containing all Node versions
rm -rf "$NVM_DIR"
# Find out current user´s shell
echo $SHELL
# Remove NVM environment references from user´s shell config (e.g. bash)
sed -i '/NVM_DIR/d' ~/.bashrc
# Remove any leftover Node binaries from PATH
sudo rm -rf /usr/local/{lib/node_modules,bin/node,bin/npm,bin/npx}
# Reload shell
exec $SHELL
📦 Package Manager
- NPM official website: npmjs.comZ
- NPM: is the default build-in Node.Js Package Manager used to install, manage, and share JavaScript libraries and tools.
- Init Project:
npm init -y - package.json
- Project’s manifest file, listing its details and dependencies.
- Example:
{ "dependencies": { "express": "^4.18.2" } } - Dependency version ranges using standard SemVer (
MAJOR.MINOR.PATCH)- Caret (^): latest minor/patch >= version
- Tilde (~): latest patch >= version
- Exact (no special character): exact version
- package-lock.json
- Locks exact versions of all dependencies to ensure consistent installations across different environments.
- Example: It guarantees
expressis version4.18.2no matter what.
- node_modules folder
- Holds all the actual code for project’s dependencies.
- Example: It contains the
expressfolder with all the framework’s files.
- Install Package:
npm install <pkg>(local),npm install -g <pkg>(global) - Remove Package:
npm uninstall <pkg> - List Packages:
npm list --depth=0(local),npm list -g --depth=0(global) - Run Scripts:
npm run <script>(from package.json) - Audit & Fix:
npm audit→npm audit fix - Check outdated packages:
npm outdated - Update to safe versions:
npm update
Express
- Express Web Framework: expressjs.com
- Unopinionated (no rigid rules on usage), minimal and fast web framework for Node.js
- Provides tools and functions to manage server setup, HTTP Requests/Routing …
CORS - Cross-Origin Resource Sharing
- CORS Overview

- CORS: Security feature in web browsers controling whether a website can request resources from different domains.
- Blocking: Website at site-A.com trying to access data from an API at api-B.com would be blocked by default without CORS.
- Allow Access: To allow access, server needs to send a special header
Access-Control-Allow-Originback to the browser.
→ can be done withNode.js/Expressandapp.use(cors());
NodeMon Utility
- Nodemon website: nodemon.io
- Live reload Node.Js app on changes
🏃 Running Apps
node app.js # Run JS script "app.js"
node -e "js code" # Run JS Code in terminal
npm run start # Run script "start" defined in package.json All cheat sheets are taken from our Udemy Online Course. Interested? Check out:
All-In-One Full Stack DevOps - From Idea to Cloud