Menu BAR

FEEL FREE TO ASK ANY PROGRAM and please mention any error if you find it

5 Feb 2024

NODE JS INTRODUCTION


1) What is Node Js?


- Node Js is an open-source server environment that runs on various platforms like Windows, Linux, Unix, Mac OS, etc.

- Node Js is a runtime environment that allows you to run JavaScript code on the server side.

- Node Js uses the V8 Javascript engine.

- Node Js is commonly used to build scalable network applications because of its event-driven, non-blocking I/O model, which makes it efficient and lightweight.



2) Why to use Node Js?

- Javascript can be used for Server-side and Client-side development (Frontend and Backend of an application).

- Node Js is an event-driven, non-blocking I/O model, which makes it efficient and scalable for handling concurrent connections. Node Js can handle multiple requests without getting blocked (Useful for real-time applications).

- V8 Javascript engine compiles JavaScript directly into machine code before executing it (High Performance).

- Since Node Js is non-blocking, and has event-driven architecture, it is inherently scalable (Can easily handle many concurrent connections).

- Plenty of resources and support available for developers who are using Node Js (Documentation, Tutorial, and more)


3) How to download Node Js?



- Node js can easily be installed from the official site - https://nodejs.org/en


4) Writing the first Node Js program.



// Import the built-in 'http' module
const http = require('http');

// Create an HTTP server that listens on port 5000
const server = http.createServer((req, res) => {
     // Set the response HTTP header with HTTP status and content type
     res.writeHead(200, {'Content-Type': 'text/plain'});

    // Write the response body ("Hello, world!")
    res.end('Hello World!!');
});

// Start the server and listen on port 5000
server.listen(5000, () => {
    console.log('Server is now running at http://localhost:5000/');
});

To run this code on your local machine:-
1) Copy and paste the above code into the file - helloworld.js
2) Open the command prompt and navigate to the folder where helloworld.js is saved
3) Run the command node helloworld.js
4) You should see the message "Server is now running at http://localhost:5000/"
5) Open any web browser and navigate to http://localhost:5000/ and you will see Hello World!!

Click Here to Learn Modules in Node Js

No comments:

Post a Comment