2021.09.02 update package.json
typescript
is open source programming language developed by microsoft.
install typescript and so on
npm install -g typescript
npm install express @types/express
npm install -D nodemon
npm install -D ts-node
and create a folder that you name it and write down npm init
at command line
as a result package.json
is created
{
"main": "index.ts",
"scripts": {
"dev": "nodemon",
"start": "tsc && node index"
},
{
"compilerOptions": {
"strict":true,
"lib":["es2015" , "es2016" , "es2017" , "es2018" , "es2019" , "es2020"],
"moduleResolution": "node"
}
}
import * as express from 'express';
import { Request, Response, NextFunction } from 'express';
const app = express();
const prod : boolean = process.env.NODE_ENV === ' production';
app.set('port', prod ? process.env.PORT : 3065);
app.get('/', (req:Request, res:Response , next:NextFunction) => {
res.send('send')
})
app.listen(app.get('port'), () => {
console.log(`server is running on ${app.get('port')}`)
})
npx ts-node index.ts
what is npx??
reference
npx ts-node index.ts
npx tsc