您的位置:首页 > Web前端 > Node.js

使用typescript开发node服务端

2017-09-21 17:39 1011 查看
使用
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/文件名
这样来启动服务
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  typescript