Open In App

What is Node?

Last Updated : 10 Apr, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Node is a JavaScript runtime environment that enables the execution of code on the server side. It allows developers to execute JavaScript code outside of a web browser, enabling the development of scalable and efficient network applications.

What is Node ?

Node is an open-source, server-side JavaScript runtime environment built on the V8 engine. It allows developers to execute JavaScript code outside of a web browser, enabling the development of scalable and efficient network applications. Known for its event-driven architecture, NodeJS is widely used for building fast, lightweight, and highly responsive server-side applications.

A Node app runs in a single process technique, without creating a brand new thread for each request. Node gives a fixed of asynchronous I/O primitives in its standard library that save you JavaScript code from blocking and commonly, libraries in NodeJS are written the usage of non-blocking off paradigms, making blocking off behavior the exception as opposed to the norm.

Reasons to choose Node.js

  • Easy to Get Started: Node.js is beginner-friendly and ideal for prototyping and agile development.
  • Scalability: It scales both horizontally and vertically.
  • Real-Time Web Apps: Node.js excels in real-time synchronization.
  • Fast Suite: It handles operations quickly (e.g., database access, network connections).
  • Unified Language: JavaScript everywhere—frontend and backend.
  • Rich Ecosystem: Node.js boasts a large open-source library and supports asynchronous, non-blocking programming

In NodeJS the new ECMAScript standards can be used without problems, as you don’t need to watch for all of your users to update their browsers – you are in price of identifying which ECMAScript version to use by converting the NodeJS model, and you may also permit specific experimental features through jogging NodeJS with flags.

Steps to Setup the Node App

Step 1: Initialize the Node App using the below command:

npm init -y

after the above step package.json file will be created.

Step 2: Create a new file with name of index.js or server.js

Example: Below is the basic example of the Node JS:

Javascript
// Import the 'http' module
const http = require('http');

// Create an HTTP server that responds with "Hello, World!" to all requests
const server = http.createServer((req, res) => {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Welcome to GeeksforGeeks!\n');
});

// Listen on port 3000 and IP address '127.0.0.1'
server.listen(3000, '127.0.0.1', () => {
  console.log('Server running at http://127.0.0.1:3000/');
});

Steps to run the Node App:

node <filename>

Output:

Screenshot-2024-01-23-122323

What is Node Example output

Advantages of Node

  • NodeJS is a open source platform and fast execution process.
  • Uses an event-driven, non-blocking I/O model, allowing for efficient handling of multiple requests simultaneously.
  • It has a rich ecosystem that provides various node package manger (npm).
  • It supports asynchronous programming, making it efficient for handling concurrent requests.
  • Relatively easy for developers already familiar with JavaScript.

Disadvantages of Node

  • NodeJS is Single threaded which means that it may not be the best choice for CPU-intensive task.
  • Due to Callback based asynchoronous programming it can lead to call back hell and complex code structure.
  • Unstable API changes between versions may impact code compatibility.
  • It is not ideal for heavily computational due to single threaded.

Learn More



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads