Node JS Introduction

Introduction to Node.js

Node.js is an open-source, cross-platform JavaScript runtime environment that allows developers to run JavaScript outside the browser. It is widely used for building scalable and high-performance web applications.

Why Use Node.js?

  • Non-blocking, event-driven architecture
  • Highly scalable for real-time applications
  • Uses JavaScript for both frontend and backend
  • Huge ecosystem with npm (Node Package Manager)

Installing Node.js

Download and install Node.js from the official website:

https://nodejs.org/

Basic Node.js Example

Create a simple web server using Node.js:


const http = require('http');

const server = http.createServer((req, res) => {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello, Node.js!');
});

server.listen(3000, () => {
    console.log('Server running at http://127.0.0.1:3000/');
});
        

Run the script and visit http://127.0.0.1:3000/ in your browser.