Skip to main content
Advertisement

Node.js (Server Side)

Recommended Version: Node.js 20 / 22 (LTS) Official Documentation: Node.js Documentation

Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. It allows JavaScript to be executed outside the browser (e.g., on a server).

1. Features of Node.js

  • Event-driven, Non-blocking I/O: It can handle many connections efficiently, making it lightweight and efficient.
  • npm (Node Package Manager): It boasts the world's largest ecosystem of open-source libraries.
  • Full-stack Development: You can write both frontend and backend using a single language, JavaScript.

2. Hello World Server (Standard Library)

const http = require('http');

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

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

3. Express Framework

The most widely used web framework in the Node.js environment.

const express = require('express');
const app = express();

app.get('/', (req, res) => {
res.send('Hello from Express!');
});

app.listen(3000);

4. Asynchronous Programming

In Node.js, it is essential to process tasks like web requests or file reading asynchronously.

  • It is important to appropriately use Callbacks, ** Promises**, and ** async/await**.

Node.js is one of the essential technologies for modern web server development.

Advertisement