89 lines
1.1 KiB
Markdown
89 lines
1.1 KiB
Markdown
# Express.js Basics
|
|
|
|
## Introduction
|
|
|
|
This project explains the basics of **Express.js**.
|
|
Express.js is a web framework built on Node.js that simplifies backend development.
|
|
|
|
Express.js is used to create web servers and APIs easily.
|
|
It provides simple methods for routing and handling HTTP requests.
|
|
|
|
---
|
|
|
|
## Features of Express.js
|
|
|
|
* Simple and easy routing
|
|
* Middleware support
|
|
* Fast server creation
|
|
* API development
|
|
|
|
---
|
|
|
|
## Example: Simple Express Server
|
|
|
|
```js
|
|
const express = require('express');
|
|
const app = express();
|
|
|
|
app.get('/', (req, res) => {
|
|
res.send('Hello from Express!');
|
|
});
|
|
|
|
app.listen(3000, () => {
|
|
console.log('Server running on port 3000');
|
|
});
|
|
```
|
|
|
|
---
|
|
|
|
## Routing Example
|
|
|
|
```js
|
|
app.get('/about', (req, res) => {
|
|
res.send('This is About Page');
|
|
});
|
|
```
|
|
|
|
---
|
|
|
|
## Middleware Example
|
|
|
|
```js
|
|
app.use((req, res, next) => {
|
|
console.log('Request received');
|
|
next();
|
|
});
|
|
```
|
|
|
|
---
|
|
|
|
## How to Run
|
|
|
|
1. Install Node.js
|
|
2. Install Express:
|
|
|
|
```
|
|
npm init -y
|
|
npm install express
|
|
```
|
|
|
|
3. Create a file `app.js`
|
|
4. Run:
|
|
|
|
```
|
|
node app.js
|
|
```
|
|
|
|
5. Open browser:
|
|
|
|
```
|
|
http://localhost:3000
|
|
```
|
|
|
|
---
|
|
|
|
## Technologies Used
|
|
|
|
* Node.js
|
|
* Express.js
|
|
* JavaScript |