Node.js & Express in VS Code
VS Code is a first-class Node.js editor. This lesson covers setting up a Node.js + Express API with TypeScript, debugging it natively, and using the REST Client extension to test endpoints.
1Project Setup
mkdir api && cd api npm init -y npm install express npm install -D typescript @types/node @types/express ts-node-dev npx tsc --init
2A Minimal Typed Express Server
import express from 'express'; const app = express(); app.use(express.json()); app.get('/health', (_req, res) => res.json({ status: 'ok' }) ); app.listen(3000);
3Debugging with Auto-Attach
Enable Auto Attach (Ctrl+Shift+P → Debug: Toggle Auto Attach) and set it to Smart. Now whenever you run a Node.js process in the integrated terminal, VS Code automatically attaches the debugger — no launch.json needed.
4Testing Endpoints with REST Client
Install the REST Client extension and create a requests.http file. Click Send Request above any request definition to fire it and see the response right in VS Code — no Postman needed.
### Get health GET http://localhost:3000/health ### Create user POST http://localhost:3000/users Content-Type: application/json { "name": "Alice" }
5Environment Variables with dotenv
Install dotenv and create a .env file. The DotENV extension adds syntax highlighting and the ENV extension provides IntelliSense for variable names referenced in your code.