环境配置
安装 node
nodeJs官网下载https://nodejs.org/zh-cn/,一路next就可以了,默认安装是在C盘
配置cnpm镜像
npm install -g cnpm --registry=https://registry.npm.taobao.org
如果想安装在其他盘,可参考 https://www.cnblogs.com/jianguo221/p/11487532.html
全局安装 typescript
npm i typescript -g
全局安装 express,可以直接用express的命令创建node-express项目
全局安装Express
npm install express-generator -g
创建node-express 项目
express server(项目名)
本文不使用express创建,这里就一笔带过了
项目创建
创建项目文件夹
mkdir server
--yes默认所有配置
npm init --yes
创建成功后,会生成一个package.json文件,暂时先不修改
引入项目初始化必要的插件
@typpes是支持ts的插件
body-parser 可以配置接收不同格式的请求,即application/json 或 application/x-www-form-urlencoded
npm i express @types/node @types/express cors @types/cors body-parser
安装开发环境需要的依赖,rimraf其实在部署运行时会用到,但其是运行前的命令,算[开发环境];
ts-node-dev 开发用这个来启动本地服务,因为node不能直接运行ts的代码
npm i -D typescript ts-node-dev rimraf
创建,并修改tsconfig.json配置
tsc --init
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "ES6", /* Specify ECMAScript target version: 'ES3