[Link] is a runtime environment that lets you run JavaScript code on the server side.
It's
built on Google Chrome’s V8 engine, which makes it very fast. Instead of just running
JavaScript in the browser, you can use it to build web servers, APIs, scripts, and more.
● Asynchronous & Event-driven: Handles many requests without blocking.
● Fast Execution: Uses the powerful V8 engine.
● Single Programming Language: JavaScript on both frontend and backend.
● npm (Node Package Manager): Access to thousands of free packages.
// [Link]
const http = require('http');
// Create a server
const server = [Link]((req, res) => {
[Link](200, { 'Content-Type': 'text/plain' });
[Link]('Hello from [Link] server!');
});
// Start the server on port 3000
[Link](3000, () => {
[Link]('Server running at [Link]
});
[Link] is a minimal and flexible [Link] web application framework that provides a robust
set of features to develop web and mobile applications.
Easy to set up routes and handle requests
Middleware support (e.g., for parsing JSON, handling errors)
Works perfectly for building RESTful APIs
Simplifies complex tasks like handling POST data, sessions, etc.
Express Demo: Hello World API
Setup
Create a folder and navigate into it:
bash
CopyEdit
mkdir express-demo
cd express-demo
1.
Initialize a [Link] project:
bash
CopyEdit
npm init -y
2.
Install Express:
bash
CopyEdit
npm install express
3.
Create [Link]
js
CopyEdit
// [Link]
const express = require('express');
const app = express();
const PORT = 3000;
// Define a simple route
[Link]('/', (req, res) => {
[Link]('Hello from [Link]!');
});
// Start the server
[Link](PORT, () => {
[Link](`Server is running at [Link]
});
Run the App
In your terminal, run:
bash
CopyEdit
node [Link]
Then open your browser and go to:
[Link]
You’ll see: "Hello from [Link]!"
With Express, you can:
● Quickly set up routes (GET, POST, etc.)
● Handle request data easily
● Build REST APIs and full-stack apps