Skip to content
Home Tutorials Roadmaps Courses
Log in Join free
Tutorials Node.js Setting Up Express
Node.js Intermediate FREE

Setting Up Express

Lesson 1 of 17 Intermediate Interactive

Express is a minimal web framework for Node.js.

Syntax

NODEJS
const express = require('express');
const app = express();

app.get('/', (req, res) => {
    res.send('Hello World!');
});

app.listen(3000);
Express.js Setup
NODE
const express = require("express");
const app = express();

app.use(express.json());

app.get("/", (req, res) => {
    res.json({ message: "Welcome to the API" });
});

app.get("/users", (req, res) => {
    res.json([
        { id: 1, name: "Alice" },
        { id: 2, name: "Bob" }
    ]);
});

app.listen(3000, () => {
    console.log("Server on port 3000");
});

Practice

1
Exercise

Practice this concept.

Answer
Write the code as shown above.

Quick Quiz

1

What did you learn?

This covers the basics.

Interview Questions

It is a fundamental Node.js feature.