Horje
What is Node?

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, Node 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 Node are written the usage of non-blocking off paradigms, making blocking off behavior the exception as opposed to the norm.

In Node 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 Node model, and you may also permit specific experimental features through jogging Node 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

Reasons to Choose Node

  • Easy to Get Started: Node is beginner-friendly and ideal for prototyping and agile development.
  • Scalability: It scales both horizontally and vertically.
  • Real-Time Web Apps: Node 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 boasts a large open-source library and supports asynchronous, non-blocking programming

Advantages of Node

  • Node 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

  • Node 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




Reffered: https://www.geeksforgeeks.org


Node.js

Related
Node.js Tutorial | Learn NodeJS Node.js Tutorial | Learn NodeJS
Mongoose Tutorial Mongoose Tutorial
Top Node Development Trends in 2024 Top Node Development Trends in 2024
How to Intialize basic template for Electron JS project using Vite and React How to Intialize basic template for Electron JS project using Vite and React
Node JS Versions Node JS Versions

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
13