Skip to content

Instantly share code, notes, and snippets.

@wilmoore
Last active July 31, 2024 05:51
Show Gist options
  • Select an option

  • Save wilmoore/adba5d7caab5abf821d105840b1d8cea to your computer and use it in GitHub Desktop.

Select an option

Save wilmoore/adba5d7caab5abf821d105840b1d8cea to your computer and use it in GitHub Desktop.
Software Engineering :: Programming :: Languages :: JavaScript :: Library :: Express :: Example

Software Engineering :: Programming :: Languages :: JavaScript :: Library :: Express :: Example

⪼ Made with 💜 by Polyglot.

related
mkdir -p your-first-program/express-typescript
cd your-first-program/express-typescript
nvm install latest
npm init -y
npm install typescript @types/express @types/node --save-dev
npm install express --save
touch server.ts
code .
npm run dev
package.json
{
  "name": "@your-first-program/express-typescript",
  "version": "1.0.0",
  "description": "",
  "main": "server.ts",
  "scripts": {
    "dev": "npx tsx watch ."
  },
  "keywords": [],
  "author": "Wil Moore III <[email protected]>",
  "license": "MIT",
  "devDependencies": {
    "@types/express": "^4.17.21",
    "@types/node": "^20.10.5",
    "typescript": "^5.3.3"
  },
  "dependencies": {
    "express": "^4.18.2"
  }
}
server.ts
import express, { Express, Request, Response } from 'express';

const app: Express = express();
const port = process.env.PORT || 3000;

app.get('/', (req: Request, res: Response) => {
  res.send('Express + TypeScript Server');
});

app.listen(port, () => {
  console.log('[server]', `Server is running at http://localhost:${port}`);
});
DEBUG

bash

DEBUG=* npm run dev

fish

DEBUG='*' npm run dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment