The Wayback Machine - https://web.archive.org/web/20240118172040/https://www.geeksforgeeks.org/node-js-introduction/
Open In App
Related Articles

Node Introduction

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Node JS is an open-source and cross-platform runtime environment for executing JavaScript code outside a browser. NodeJS is not a framework and it’s not a programming language. Node.js is used to build back-end services like APIs like Web App or Mobile App. It’s used in production by large companies such as Paypal, Uber, Netflix, Walmart, and so on.

Node.js = Runtime Environment + JavaScript Library

Basic Concepts of Node:

The following diagram depicts some important parts of Node.js that are useful and help us understand it better.

How Node works?

Node accepts the request from the clients and sends the response, while working with the request node.js handles them with a single thread. To operate I/O operations or requests node.js use the concept of threads. Thread is a sequence of instructions that the server needs to perform. It runs parallel on the server to provide the information to multiple clients. Node.js is an event loop single-threaded language. It can handle concurrent requests with a single thread without blocking it for one request.

Advantages of Node:

  1. Easy Scalability: Easily scalable the application in both horizontal and vertical directions.
  2. Real-time web apps: Node.js is much more preferable because of faster synchronization. Also, the event loop avoids HTTP overloaded for Node.js development.
  3. Fast Suite: NodeJS acts like a fast suite and all the operations can be done quickly like reading or writing in the database, network connection, or file system
  4. Easy to learn and code: NodeJS is easy to learn and code because it uses JavaScript.
  5. Advantage of Caching: It provides the caching of a single module. Whenever there is any request for the first module, it gets cached in the application memory, so you don’t need to re-execute the code.

Reason to Choose Node:

There are other programming languages also which we can use to build back-end services so what makes Node.js different I am going to explain.

  • It’s easy to get started and can be used for prototyping and agile development
  • It provides fast and highly scalable services.
  • It uses JavaScript everywhere, so it’s easy for a JavaScript programmer to build back-end services using Node.js
  • Large ecosystem for open source library and has asynchronous or non-blocking nature.

Application of NodeJS: NodeJS should be preferred to build Real-Time Chats, Complex Single-Page applications, Real-time collaboration tools, Streaming apps, JSON APIs based application.

Example: Below is the basic code example of the nodejs server.

Javascript




// Importing the http module
const http = require('http');
 
// Creating a server
const server = http.createServer((req, res) => {
    // Setting the content type to HTML
    res.writeHead(200, { 'Content-Type': 'text/html' });
 
    // Sending the HTML response
    res.end('<h1>Hello GFG</h1>');
});
 
// Listening on port 3000
const PORT = 3000;
server.listen(PORT, () => {
    console.log(`Server running at http://localhost:${PORT}/`);
});


Output:

basic-nodejs

Output

Express – Most used framework based on Node:

Express is a framework that works on top of Node.js web server functionality to simplify its APIs and add helpful new features. It makes it easier to organize your application’s functionality with middleware and routing. It adds helpful utilities to Node.js HTTP objects and facilitates the rendering of dynamic HTTP objects.

if you want to learn more about the express then follow the reference article: Express JS

Learn more about Node JS:


Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 03 Jan, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials