1. npx tsc
node dist/index.js
2.在开发环境中,每一次运行上述命令来编译和运行都是很烦人的。为了使这个过程更容易,你需要安装一个叫做ts-node 的包。
npm install -D ts-node
继续配置你的package.json 脚本标签并启动构建命令
"scripts": { "start": "ts-node ./src/index.ts" }
现在你可以运行npm start
3.当开发一个广泛的应用程序时,建议用观察参数钩住你的项目,这将有助于你在对代码结构进行修改和保存时重新启动你的服务器。
npm install -D ts-node-dev
要使用它,请修改package.json 脚本标签,如下所示。
package.json修改如下
"scripts": { "dev": "ts-node-dev --respawn ./src/index.ts" }