How to create an Express API with TypeScript

foo

bar

import express from 'express';
import helmet from 'helmet';
import cors from 'cors';
import router from './config/router';
import dotenv from 'dotenv';
import path from 'path';

dotenv.config({
  path: path.join(__dirname, '../.env'),
});

const app = express();

const port = process.env.PORT || 3000;

app.use(helmet());

app.use(express.json());

app.use(express.urlencoded({extended: true}));

app.use(cors());
app.options('*', cors());

app.use(router);

app.listen(port, () => {
  console.log(`Server running at http://localhost:${port}`);
});