Creating Your First Server
Swipe to show menu
To start using Express, you first need to install it in your project.
In your project folder, run:
npm install express
After installation, you can create a basic server.
const express = require("express");
const app = express();
app.listen(3000, () => {
console.log("Server is running on port 3000");
});
Here's what happens in this code:
You import Express and create an application using express().
Then you start the server using app.listen().
The number 3000 is the port where your server will run. When the server starts, it listens for incoming requests on that port.
To run the server, execute your file with Node.js. If everything works, you will see the message in the terminal.
At this point, the server is running, but it does not handle any requests yet. That will be added in the next step.
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat