世界上最伟大的投资就是投资自己的教育

全场限时 5 折

首页服务器部署
宏 · 大罗

pm2 怎样配置运行 ts-node (Typescript) 网上找的,一直没配置成功,怎么办?

发布于3736 次阅读

pm2 怎样配置运行 ts-node (Typescript) 网上找的,一直没配置成功,怎么办? 随风大神...

一、背景
node 服务使用 Typescript 进行开发,准备采用 pm2 进行启动。

需要解决的问题:
Typescript 解释器
ts-node 支持路径映射

二、依赖库
ts-node
tsconfig-paths

三、配置详情
module.exports = {
apps: [{
// 指定解释器
interpreter: './node_modules/.bin/ts-node',
// 解释器参数 -P 表示项目路径,会自动使用项目的 tsconfig.json
interpreter_args: '-P ./server -r tsconfig-paths/register',
cwd: './',
env: {
NODE_ENV: 'development'
},
env_production: {
NODE_ENV: 'production'
},
kill_timeout: 10000,
name: 'caas_server',
script: './server/app.ts',
wait_ready: true,
watch: false,
// watch: ['server'],
ignore_watch: ['node_modules'],
watch_options: {
"usePolling": true
}
}]
};

3.1、interpreter
解析器路径,默认值为 node 的路径
我们使用 ts-node 作为 Typescript 的解释器

3.2、interpreter_args
解释器参数
-P ./server 指定下 ts 项目路径,会使用项目下的 tsconfig.json 配置文件
-r tsconfig-paths/register ts-node 本身不支持 tsconfig 配置的路径映射,所以需要 tsconfig-paths 来帮支持

3.3、cwd
项目路径

3.4、script
运行的脚本

本站文章均为原创内容,如需转载请注明出处,谢谢。

1 条回复
  • 宏 · 大罗
    宏 · 大罗 #1

    pm2 start npm --name 'BMS' -- run start --watch 终于找到这语句,可以执行。就是 npm run start --> ts-node src/index.ts。

喜欢
统计信息
    学员: 29228
    视频数量: 1985
    文章数量: 489

© 汕尾市求知科技有限公司 | Rails365 Gitlab | Qiuzhi99 Gitlab | 知乎 | b 站 | 搜索

粤公网安备 44152102000088号粤公网安备 44152102000088号 | 粤ICP备19038915号

Top