npm i express cors dotenv && npm i -D typescript tsc ts-node-dev @types/express @types/node @types/cors
//2)building tsconfig.json
tsc --init
//3) inside tsconfig.json
{
"compilerOptions": {
"target": "es6",
"module": "CommonJS",
"outDir": "./dist",
"rootDir": "./",
"strict": true,
"noImplicitAny": false,
}
}
//4) package.json
"scripts": {
"dev": "ts-node-dev --clear server.ts",
"build": "tsc",
"start": "node dist/server.js"
},
//yarn add express cors
//yarn add @types/cors @types/express --dev
import express from 'express';
import cors from 'cors';
const app = express();
const router = express.Router()
router.get('/', function (req, res) {
res.send("All systems operational")
})
app.use(cors());
app.use(router);
app.listen(3000, () => console.log('Listening on port 3000'));
$ npm install -g typescript-express-starter
"dev":"ts-node-dev --respawn --transpile-only src/app.ts "