admin管理员组文章数量:1253693
I have a NodeJS application which has only typescript files in it, no js files. I want to run in on my server in the background.
How can I archive that?
I tried using the npm package called forever
but it only works with js files as it doesn't understand the typescript code.
I have a NodeJS application which has only typescript files in it, no js files. I want to run in on my server in the background.
How can I archive that?
I tried using the npm package called forever
but it only works with js files as it doesn't understand the typescript code.
- You need to pile the typescript files into javascript. – Ceres Commented Sep 18, 2019 at 16:32
- 2 You don't run Typescript directly. you transpile it to Javascript and run that. – jfriend00 Commented Sep 18, 2019 at 16:33
- 1 @Ceres how can i do that? – SwiftiSwift Commented Sep 18, 2019 at 16:33
- 1 @jfriend00 how can i do that? – SwiftiSwift Commented Sep 18, 2019 at 16:34
- It is all spelled out here: typescriptlang and github./Microsoft/…, – jfriend00 Commented Sep 18, 2019 at 16:47
4 Answers
Reset to default 13You could use forever
in bination with ts-node
.
Here is a link to the npm package ts-node
I would suggest using the following mand:
forever start -v -c ts-node app.ts
Where -v/--verbose
is for turning on the verbose messages from Forever.
And -c
is the COMMAND to execute which is default is node
This question is so old and forever now discourages to use it.
For new installations we encourage you to use pm2 or nodemon
Here is a quick tutorial on how to run your Typescript project as a background process.
Install PM2 globally:
npm install pm2 -g
Build your sources with Typescript default config:
tsc
You will have a new directory dist that contains your js files.
pm2 start dist/app.js
Bonus: you can monitor your app with the following mand.
pm2 monit
first use
npm install -g ts-node
then use
forever start -v -c ts-node app.ts
it shuld start now
The two production quality remendations I would make are:
- Turn it into a docker container
- Write a systemd service
Those are by far the best options. If for some reason this doesn't work:
- pm2
- supervisord
本文标签: javascriptHow to run Typescript files on Server in backgroundStack Overflow
版权声明:本文标题:javascript - How to run Typescript files on Server in background? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740777334a2284497.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论