Asked 7 years ago
17 Jan 2017
Views 1116
noob

noob posted

Node JS over JavaScript

what is plus in Node JS over JavaScript ? because as i learn Node.js and i see that it work same as JavaScript . Node JS also run JavaScript . so why one made Node JS ? what is pros and cons of Node JS over JavaScript ?
Rasi

Rasi
answered Nov 30 '-1 00:00

Node JS is also JavaScript + additional c++ code .

JavaScript is made on C++ / C , but have designed for web application usage and so it do not have support for file handling or efficient socket programming or database handling facility.
Over JavaScript
Node JS allow some good feature which is not allowed in JavaScript and which make Node JS to special JavaScript

1. File manipulation

following code is for Node JS , Which can delete folder . which is not possible In JavaScript .

const fs = require('fs');
fs.unlinkSync('/tmp/hello');
console.log('successfully deleted /tmp/hello');


so by Node JS , One can read / write / delete server 's file .which is plus over JavaScript

1. Socket Level Programming
Socket Level Programming is not possible in JavaScript . Socket connection and communication upon on it work like charm in Node JS

var server = net.createServer((socket) => {
  socket.end('goodbye\n');
}).on('error', (err) => {
  // handle errors here
  throw err;
});

// grab a random port.
server.listen(() => {
  console.log('opened server on', server.address());
});


mostly chat like web app work good with Node JS , because it allow socket connection and communicate with each other which make chat web app faster and easy to use.

3. Load Balancing
Load Balancing possible in the Node JS because Node JS have Cluster .
A single instance of Node.js runs in a single thread. To take advantage of multi-core systems the user will sometimes want to launch a cluster of Node.js processes to handle the load.

Load Balancing not possible in JavaScript as we do in Node JS


4. Database manipulation
in Node JS , not needed additional server side language like PHP to communicate with Database. because Node JS do database connection and communication directly

some implementation

node-postgres - Non-blocking PostgreSQL client for node.js

mysql - A pure node.js JavaScript Client implementing the MySql protocol.

other example of miscellaneous use of JavaScript by Node JS

One can make zip by JavaScript By Node JS
use of zlib to make gzip file ::

const gzip = zlib.createGzip();
const fs = require('fs');
const inp = fs.createReadStream('input.txt');
const out = fs.createWriteStream('input.txt.gz');
inp.pipe(gzip).pipe(out);




lots of module available for Node JS which make it limit less

Post Answer