Installing Express
5 min read
Installing Express
Before you install Express, make sure you have Node.js 20 or later. Start by initialising a new project and installing Express as a production dependency.
bash
mkdir my-api && cd my-api
npm init -y
npm install expressIf you are using TypeScript — which CPCODELAB recommends for all backend projects — you should also install the type definitions for Express.
bash
npm install --save-dev typescript @types/node @types/express ts-node-dev
npx tsc --initAdd "type": "module" to your package.json only if you want native ESM. Otherwise keep the default CommonJS — it is simpler to configure and fully supported.
Your package.json scripts section should look like this for a TypeScript development workflow.
json
{
"scripts": {
"dev": "ts-node-dev --respawn src/index.ts",
"build": "tsc",
"start": "node dist/index.js"
}
}Ready to test yourself?
Practice Express— quiz & coding exercises