<nodejs_express_setup> <title>How to Set Up a Basic Node.js Backend in a Backend Folder</title> 1 Create a New Directory for the Backend mkdir backend cd backend 2 Initialize a New Node.js Project npm init -y 3 Install Required Dependencies npm install express npm install cors 4 Create a Basic Express Server <code_file> index.js <![CDATA[ const express = require('express'); const cors = require('cors');
const app = express(); const PORT = 4000; // You can choose any port that's not in use
// Middleware to parse JSON requests app.use(express.json());
// Middleware to handle CORS (allow requests from your frontend) app.use(cors());
// Example route app.get('/', (req, res) => { res.send('Hello from the backend server!'); });
// Start the server
app.listen(PORT, () => {
console.log(Server is running on http://localhost:${PORT}
);
});
]]>
</code_file>
5
Start the Backend Server
node index.js