- Create an empty directory for your project and move in it.
mkdir project
cd project
- Initialize npm
npm init -y
- Install typescript as a dev dependency.
npm i -D typescript
- Create a typescript config file
npx tsc --init
the D flag installs it as a dev dependency
- Install express (dependency) and it's types (dev dependency)
npm i express
npm i -D @types/express
- Create a src folder and create a new file 'index.ts' and copy the following code.
import express from "express";
const app = express();
app.get("/", (req, res) => {
res.send("Hello World");
});
app.listen(5000, () => {
console.log("server started");
});
- Open tsconfig.json and find "outDir", uncomment it, and update its value to dist
"outDir": "./dist"
- Install nodemon (dev dependency)
npm i -D nodemon
- Install ts-node (dev dependency)
npm i -D ts-node
- Open package.json update main to be
"main": "dist/index.js"
and add the following under scripts
"start": "nodemon src/index.ts"
- Install eslint (dev dependency)
npm i -D eslint
- Create a eslint config file
npx eslint --init
Choose all the config from the prompt
- Add lint to script in package.json
"lint": "eslint . --ext .ts"
Top comments (0)