Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Creating Your First Server | Section
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Building APIs with Express.js

bookCreating 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.

question mark

What does app.listen(3000) do?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 2

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Section 1. Chapter 2
some-alt