Express.js Web API Basics
Welcome to Shrash Studio Learning. In this tutorial, we will learn Express.js Introduction and First API Setup using super simple English, practical examples, and beginner-friendly explanations.
What is Express.js?
Express.js is one of the most popular backend frameworks in Node.js.
It is used for:
- Building APIs
- Creating backend servers
- Handling HTTP requests
- Building web applications
Express.js makes backend development fast, simple, and beginner friendly.
Step 1 - Create Project Folder
Open terminal and create a new folder.
mkdir expressjs-tutorial
Step 2 - Move Inside Folder
cd expressjs-tutorial
Step 3 - Initialize Node.js Project
Run the following command:
npm init -y
Step 4 - Install Express.js
npm install express
Step 5 - Install Nodemon
npm install -D nodemon
Step 6 - Create Source Folder
mkdir src
Step 7 - Import Express
import express from 'express';
Step 8 - Create Express Application
const app = express();
Step 9 - Configure Port
const port = process.env.PORT || 3000;
Step 10 - Create First Route
app.get('/', (req, res) => {
res.send('Hello World');
});
Step 11 - Start Express Server
app.listen(port, () => {
console.log(`Running on port ${port}`);
});
Final Working Express.js Application
import express from 'express';
const app = express();
const port = process.env.PORT || 3000;
app.get('/', (req, res) => {
res.send('Hello World');
});
app.listen(port, () => {
console.log(`Running on port ${port}`);
});
Advantages of Express.js
| Feature | Benefit |
|---|---|
| Lightweight | Fast performance |
| Simple | Easy learning |
| Flexible | Easy project structure |
Important Tips
- Use nodemon during development
- Keep routes organized
- Practice API development regularly
Interview Answer
If interviewer asks "What is Express.js?"
"Express.js is a lightweight backend framework for Node.js used for creating APIs and backend applications quickly."
"Express.js is a lightweight backend framework for Node.js used for creating APIs and backend applications quickly."
Summary
Express.js is one of the easiest and most powerful frameworks for backend development using Node.js.
It helps developers create APIs, manage requests, and build scalable applications easily.