Skip to content

Instantly share code, notes, and snippets.

@max-programming
Created November 11, 2022 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save max-programming/a109596613ce08ad133f62b97e0c4547 to your computer and use it in GitHub Desktop.
Save max-programming/a109596613ce08ad133f62b97e0c4547 to your computer and use it in GitHub Desktop.

Steps for generating Express app with TypeScript

Initialize the app

npm init -y

Install TypeScript Dependencies

npm i typescript ts-node-dev @types/node -D

Generate TSConfig

npx tsc --init

Install Express and it's types

npm i express
npm i @types/express -D

Basic express code (in src/app.ts)

import express from 'express';

const app = express();

const port = 3000;

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

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`);
});

Adding Scripts in package.json

Add dev script

"dev": "tsnd src/app.ts --respawn --transpile-only --exit-child",

Add build script

"build": "tsc"

Add start script (Production)

"start": "node dist/app.js"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment