NodeJS install
2 min readJul 17, 2023
Easy one
What is Node.js?
- an open source server environment
- free and runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
- uses JavaScript on the server
What to do with Node.js?
- generate dynamic page content
- create, open, read, write, delete, and close files on the server
- collect form data
- add, delete, modify data in your database (SQL, MongoDB)
- GPIO, General Purpose Input Output, at Raspberry Pi
Install (or upgrade) the NVM — Node Version Manager
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/<version>/install.sh | bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash
or
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash
export NVM_DIR="$HOME/.nvm"
source ~/.bashrc
nvm ls
nvm --version
NVM will be installed at ~/.nvm, if you need to upgrade it later, run it:
cd ~/.nvm/
git fetch --tags origin
git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)` && \. "$NVM_DIR/nvm.sh"
nvm ls-remote
nvm --version
Install latest (also upgrade) Node.js with NVM
nvm ls-remote
nvm install node
nvm use node
node --version
And upgrade the NPM — Node Package Manager
nvm install-latest-npm
Check packages installed
npm list
OR
npm list --depth=0
OR
npm list -g
OR
npm list -g --depth=0
Check Outdated Packages
npm outdated
OR
npm outdated --depth=0
OR
npm outdated -g
OR
npm outdated -g --depth=0
Update Packages
npm update -g
OR
npm update -g <package_name>
<aliases: up, upgrade, udpate>
Create a file hello.js
cat >> hello.js
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('Hello World!');
}).listen(8080);
Start a node server:
node hello.js
Access your local host:
http://localhost:8080/
Hello World!
More Node.js documentation at https://www.w3schools.com/nodejs/default.asp
More NPM documentation at https://docs.npmjs.com/about-npm