how to install node 12/14/16 version in ubuntu
Step 1) Update apt repository and setup node 16.x
$ sudo apt update
$ sudo apt -y install curl dirmngr apt-transport-https lsb-release ca-certificates
$ curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
Step 2) install nodejs
sudo apt -y install nodejs
sudo apt -y install gcc g++ make
node --version
npm --version
Check Node Working Or Not
Step 1) Create Directory
$ mkdir ~/node_projects
$ cd ~/node_projects
Step 2) Create a new file called hello-node.js with the nano or vim command.
$ nano hello-node.js
- paste below contant in hello-node.js file
const http = require('http');
const hostname = '127.0.0.1';
const port = 4000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello, World!\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Step 3) Run below command
node hello-node.js
- Server running at http://127.0.0.1:4000
Step 4) Finally write http://127.0.0.1:4000 in your browser
No comments:
Post a Comment
testing