Introduction
Before you can build a REST API, you need a working project foundation. This lesson walks through every step: initializing a Node.js project, installing Express, writing a minimal server, and confirming it actually works. By the end you will have a running server that responds to HTTP requests — the base every subsequent lesson builds on.
This assumes Node.js (v18 or later) and npm are already installed on your machine. Run these two commands to verify before continuing:
If either command returns an error, download Node.js from nodejs.org (npm is bundled with it).
Initializing the Project
Create a new directory for your project and initialize it as a Node.js package. The init command generates a package.json file, which tracks your project metadata and dependencies.
The -y flag accepts all defaults so you are not prompted for project name, version, and so on. You can edit package.json manually at any time. At this point your directory contains only that one file — no code yet.
Next, install Express:
This downloads Express and its dependencies into a node_modules folder and records the dependency in package.json under "dependencies". You will also see a package-lock.json created — this locks exact dependency versions so every developer on your team installs identical packages.
Building the First Server
Create a file called server.js in the project root. This file is your application entry point.
Walking through each part: require('express') imports the framework. Calling express() creates an application instance stored in app. app.get() registers a route handler — the first argument is the URL path, the second is a callback that receives the request object (req) and response object (res). res.json() sends a JSON response and sets the Content-Type header automatically. Finally, app.listen() binds the server to a port and starts accepting connections.
Start the server:
You should see the console message. Open a browser to http://localhost:3000 or use curl:
Expected output:
Improving the Development Workflow
Restarting the server manually after every code change is tedious. Install nodemon as a development dependency — it watches your files and restarts automatically when it detects changes.
Then add a dev script to package.json:
Now run the server in development mode:
Edit server.js, save, and nodemon restarts the process without you doing anything. The start script remains for production use where nodemon is not appropriate.
One more improvement: parse incoming JSON request bodies. Express does not do this by default. Add this middleware line before your routes:
Without this, req.body will be undefined when a client sends a POST request with a JSON payload. Adding it now saves debugging confusion later.
Summary
You now have a fully functional Express project: a package.json tracking dependencies, Express installed, a server.js that listens on port 3000, a working GET route, nodemon for fast iteration, and JSON body parsing enabled. This is the exact skeleton used as the starting point for every REST API pattern covered in the rest of the course. The next lesson moves into routing — defining multiple endpoints and organizing them cleanly as the API grows.