0

I have npm installed forever, also npm installed ts-node, and npm installed typescript to try and get this API running. I have been trying " forever start -v -c ts-node ./lib/server.ts" or "forever start -v -v ts-node ./lib/app.ts" and many variations to run it but forever logs throws an error

events.js:187
      throw er; // Unhandled 'error' event
      ^

Error: spawn tail ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)
    at onErrorNT (internal/child_process.js:456:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:270:12)
    at onErrorNT (internal/child_process.js:456:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn tail',
  path: 'tail',
  spawnargs: [ '-n', 100, 'C:\\Users\\*****\\.forever\\P0EG.log' ]

If I follow that log file it says

'ts' is not recognized as an internal or external command, operable program or batch file. error: Forever detected script exited with code: 1

I have been working on this for days and cant seem to figure out the solution, I need to run the server in the background without the need to have VSCode or any other window open since this will run on a VM and need it to always be up for the client to be able to hit its endpoints. this is the folder structure of the project, and the client side is a Angular project if that matters

enter image description here

dEv93
  • 163
  • 1
  • 3
  • 11
  • Why are you running a .ts file? The `nodejs` file should be a `.js` file. `Forever` is only to keep a `nodejs` server running and restarting should it crash. https://stackoverflow.com/a/32944853/185672 – Phil Apr 03 '20 at 16:49
  • @Phil this project was started by another dev and he thought that if the frontend was angular which uses type script why not also use .ts files in the backend, that was his logic, i am not locked in on using forever if there is another way to achive my goal, im open, forever is just what Ive seen most people use. So would i need to create the equivalent .js file? – dEv93 Apr 03 '20 at 16:52

2 Answers2

0

Build Angular into a dist folder using ng build --prod.

Angular.json file should include instructions on how to do this

"options": {
    "outputPath": "dist",

    "index": "... index.html",
    "main": "... main.ts",

    "assets": [
        ... assets file location
    ],
    "styles": [
         ... your css
    ],
    "scripts": []
}

Have your node server to point to that directory:

/* init static directory */
app.use(express.static(path.join(__dirname, 'dist')));
Phil
  • 10,948
  • 17
  • 69
  • 101
0

First of all to fix this I had to run 'npm run prod' this triggered an npm build that gave me the dist folder that I needed with the app.js and server.js files

Then I found that there was an issue with the newest version of Forever being able to read file spaces in the 'C:Program Files' so we downgraded to forever v1.0.1 once i did this i ran 'forever start server.js' and this got my api running on the correct port and my Angular application was able to hit it.

dEv93
  • 163
  • 1
  • 3
  • 11