Getting Started
Building a REST API is a fundamental skill for any backend developer.
Setting up the project
First, initialize your project and install the necessary dependencies:
Code
npm init -y
npm install express mongoose dotenv cors
npm install -D nodemon
Creating the Server
Create a server.js file:
Code
const express = require('express');
const app = express();
app.use(express.json());
app.get('/api/health', (req, res) => {
res.json({ status: 'ok' });
});
app.listen(3000, () => console.log('Server running on port 3000'));
Next Steps
In the next module, we will connect this API to MongoDB and implement JWT authentication.