Home › Learn › Node.js and Express: Build a Back End API from Scratch
Node.js and Express: Build a Back End API from Scratch
Free Node.js and Express course. 15 lessons: async code, routes, middleware, REST API, MongoDB, JWT login, security, tests and deployment with tested code.
Beginner · 15 lessons
Node.js Basics What Is Node.js? Install It and Run Your First Script - Learn what Node.js is, what it is used for, how to install it, and how to run JavaScript on your own computer outside the browser. Beginner friendly.Modules, npm and package.json Explained - Understand ES modules with import and export, how npm installs packages, what package.json and node_modules are, and how to add scripts to your project.Working with Files and Paths: fs, path and JSON - Read and write files with node:fs/promises, build safe file paths with node:path, store data as JSON and handle errors such as a missing file.Async JavaScript in Node: Promises, async/await and the Event Loop - Understand why Node.js is asynchronous, how promises and async/await work, how to handle errors, run tasks in parallel and avoid blocking the event loop.Your First HTTP Server with Plain Node.js - Learn how HTTP requests and responses work and build a small server with node:http. See why frameworks like Express exist and how to test with curl.Express Your First Express Server: Routes, Requests and Responses - Install Express, create a server with routes, learn what req and res contain, send text and JSON, and restart automatically while you edit with node --watch.Express Routing: URL Params, Query Strings and Routers - Learn how Express routes work: method and path, URL parameters, query strings, status codes, route order and splitting routes into files with Router.Express Middleware Explained: next(), Logging and express.json() - Understand Express middleware: functions that run in order on every request. Write a logger, parse JSON bodies and apply middleware to chosen routes.Build a REST API: Create, Read, Update and Delete Tasks - Build a complete Express task API with routes to create, read, update and delete tasks, correct status codes and curl tests. Data is kept in memory first.Validation and Error Handling in Express - Never trust client data: validate request bodies, return clear 400 and 404 errors, and write one central Express error handler with no leaked stack traces.Data, Login and Going Live Environment Variables and Saving Your Data to a File - Keep settings and secrets out of your code with environment variables and a .env file, and save API data to a JSON file so it survives a restart.MongoDB and Mongoose: Store Your API Data in a Real Database - Connect your Express API to MongoDB with Mongoose: schemas, models, CRUD queries, validation and bad ids. Use a local install or an Atlas cluster.User Login: Password Hashing and JSON Web Tokens - Add registration and login to your API: hash passwords with bcrypt, issue and verify JSON Web Tokens, and keep each person’s tasks private.Secure Your Express API: CORS, Helmet and Rate Limiting - Harden your Express API: set CORS for your front end, add Helmet headers, limit repeated requests, cap body size and avoid common mistakes.Test and Deploy Your Node.js API: node:test, pm2 and nginx - Write API tests with the built-in node:test runner, then take your Express API live with pm2, an nginx proxy, HTTPS and a launch checklist.