Skip to main content

How to install Node.js on Ubuntu

Install node.js using default repository of Ubuntu

Ubuntu 16.04 contains a version of node.js in its default repository.
The version of this node.js is 4.2.6

sudo apt-get update
sudo apt-get install nodejs

To install node.js package manager npm

sudo apt-get install npm

To check node.js version. Type this command -

node -v

npm -v


Install node.js using PPA

Step 1: Adding PPA
$ curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
Step 2: Install Node.js
$ sudo apt-get install nodejs
Now you have done. :)


Lets try an example of node.js

Create a file http_server.js

$ vim http_server.js
add the following content
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World');
}).listen(3001, "127.0.0.1");
console.log('Server running at http://127.0.0.1:3001/');

Now to run the code on browser

node http_server.js

In browser type in url http://127.0.0.1:3001/




Comments

Popular posts from this blog

Use Case Diagram for Online Book Store

Online Movie Ticket Booking Sequence Diagram

Linear search & Binary search using Template

Write a program to search an element from a list. Give user the option to perform Linear or Binary search. Use Template functions. #include<iostream> using namespace std; template <class T> void Lsearch(T *a, T item, int n) { int z=0; for(int i=0;i<n;i++) { if(a[i]== item) { z=1; cout<<"\n Item found at position = "<<i+1<<"\n\n"; } else if(z!=1) { z=0; } } if(z==0) cout<<"\n Item not found in the list\n\n"; } template <class T> void Bsearch(T *a, T item, int n) { int beg=0,end=n-1; int mid=beg+end/2; while((a[mid]!=item) && (n>0)) { if(item>a[mid]) beg=mid; else end=mid; mid=(beg+end)/2; n--; } if(a[mid]==item) cout<<"\n Item found at position = "<<mid+1<<"\n\n"; else cout<<"\n Item not found in the list\n\n"; } void main() { int iarr[10] = {2,42,56,86,87,99,323,546,767,886};