使用
typescript
开发node
服务器的基本配置
一、使用工具或者环境
- 1、
window
系统 - 2、
webstorm
编辑器
二、工具的基本配置
1、配置
webstorm
根据配置文件自动编辑typescript
文件
三、创建一个项目的
- 1、
npm init -y
生成一个package.json
文件 2、
tsc --init
生成tsconfig.json
文件**基本的配置** { "compilerOptions": { "target": "es5", "module": "commonjs", "lib": ["es6"], "outDir": "build", "strict": true, "experimentalDecorators": true, "emitDecoratorMetadata": true }, "exclude": [ "node_modules" ] }
3、
npm install express --save
安装express
的包- 4、
npm install @types/express --save-dev
安装express
的typescript
文件 5、创建一个
hello.ts
文件import * as express from 'express'; const app = express(); app.get('/', (req, res) => { res.send('hello word'); }); app.listen(3000, 'localhost', () => { console.log(`express服务已经启动:localhost:5000`); })
6、启动服务
- 7、其他关于
node
操作可以参考我之前的博客
四、补充说明(配置自动启动node
服务)
- 1、
npm install nodemon -g
全局安装一个文件 - 2、
nodemon build/文件名
这样来启动服务