express typescript settings

BackEnd_Ash.log·2021년 8월 5일
0

2021.09.02 update package.json

📌 typescript

typescript is open source programming language developed by microsoft.

📌 setting

👉 npm init & package.json

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

👉 package.json

{
  "main": "index.ts",
  "scripts": {
    "dev": "nodemon",
    "start": "tsc && node index"
  },

👉 tsconfig.json

{
	"compilerOptions": {
		"strict":true,
		"lib":["es2015" , "es2016" , "es2017" , "es2018" , "es2019" , "es2020"],
		"moduleResolution": "node"
	}
}

📌 index.ts

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

👉 dev env

npx ts-node index.ts

👉 deploy env

npx tsc

profile
꾸준함이란 ... ?

0개의 댓글