pm2.json文件配置{ “apps”:{ “name”:“nodeTest”, “interpreter”:"./node_modules/.bin/ts-node", “cwd”:"./", “script”:"./app.ts", “output”: “./output.log”, “error”: “./error.log”, } } pm2 start pm2.json输出error.log文件报错
请问大家是先tsc编译成js,然后在pm2管理吗?
一般编译成js再启动
- script: ./dist/main.js
name: test
interpreter: node
interpreter_args: -r tsconfig-paths/register
cwd: ./
exec_mode: cluster_mode
instances: max
watch_options:
followSymlinks: false
error_file: ./log/integral-error.log
out_file: ./log/integral-out.log
pid_file: ./log/integral-piZd.log
log_date_format: YYYY-MM-DD HH:mm:ss
env:
NODE_ENV: production
pm2 install typescript
使用ts写的话,尽量先编译成js,这样在nodejs环境下就完美运行了
分情况,但是最好都编译成js吧,
有的时候fork不起来,就跑cluster模式
prod: pm2 start app.js -i 1 --name "demo"
dev: pm2 start npm --no-automation --name {app name} -- run {script name}
反正我是这样的
写pm2.json文件,编译器用ts-node也行的。两者之间性能如何没有深入研究
各位老板,我之前用的也是先编译为js,然后在运行.然后引入了 typeorm 包.编译的时候就报错了; 还有就是node 在 webStorm怎么打断点? 我没有找到方法;下面是我报错的信息; 我用ts-node 可以跑起,新人求教
E:\app\node\node.exe E:\app\node\node_modules\npm\bin\npm-cli.js run dev --scripts-prepend-node-path=auto
nodetsserver@1.0.0 dev E:\workFile\nodeAndVueAndMysql\nodeTsServer supervisor -w dist dist/index.js
Running node-supervisor with program ‘dist/index.js’ –watch ‘dist’ –extensions ‘node,js’ –exec ‘node’
Starting child process with 'node dist/index.js’ Watching directory ‘E:\workFile\nodeAndVueAndMysql\nodeTsServer\dist’ for changes. Press rs for restarting the process. 创建对象 监听接口 (node:8376) UnhandledPromiseRejectionWarning: E:\workFile\nodeAndVueAndMysql\nodeTsServer\entity\CaptchasEnt.ts:1 (function (exports, require, module, __filename, __dirname) { import {Entity, PrimaryGeneratedColumn, Column, OneToOne, JoinColumn} from “typeorm”; ^
SyntaxError: Unexpected token { at new Script (vm.js:80:7) at createScript (vm.js:274:10) at Object.runInThisContext (vm.js:326:10) at Module._compile (internal/modules/cjs/loader.js:664:28) at Object.Module._extensions…js (internal/modules/cjs/loader.js:712:10) at Module.load (internal/modules/cjs/loader.js:600:32) at tryModuleLoad (internal/modules/cjs/loader.js:539:12) at Function.Module._load (internal/modules/cjs/loader.js:531:3) at Module.require (internal/modules/cjs/loader.js:637:17) at require (internal/modules/cjs/helpers.js:22:18) (node:8376) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:8376) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.