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.

Share Improve this question edited Sep 19, 2019 at 8:36 Max 1,5231 gold badge17 silver badges29 bronze badges asked Sep 18, 2019 at 16:30 SwiftiSwiftSwiftiSwift 8,75712 gold badges67 silver badges109 bronze badges 5
  • 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
Add a ment  | 

4 Answers 4

Reset to default 13

You 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:

  1. Turn it into a docker container
  2. Write a systemd service

Those are by far the best options. If for some reason this doesn't work:

  1. pm2
  2. supervisord

本文标签: javascriptHow to run Typescript files on Server in backgroundStack Overflow