2

I start my forever with "forever start app.py" and then check with "forever list" and the app is STOPPED and does not restart. When I start it "forever start --minUptime 1000 --spinSleepTime 1000 app.py" it restarts it over and over again every .8 seconds or less. If I run my app outside of forever it works perfectly fine. I've restarted my computer and the same thing happens. Any idea what the problem might be?

I uninstalled forever and even Node.JS and reinstalled and when I tried to forever start again, I came across this error:

SyntaxError: Unexpected token import
at new Script (vm.js:51:7)
at createScript (vm.js:136:10)
at Object.runInThisContext (vm.js:197:10)
at Module._compile (internal/modules/cjs/loader.js:618:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
at Module.load (internal/modules/cjs/loader.js:566:32)
at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
at Function.Module._load (internal/modules/cjs/loader.js:498:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:695:10)
at startup (internal/bootstrap/node.js:201:19)
error: Forever detected script exited with code: 1

UPDATE

When I forever stop 0 the stopped process, even though it deletes it, it gives an error that reads:

 error:   Forever cannot find process with id: 0

After that, when I check forever log, I get:

error:   Cannot start forever
error:   script C:\Users\Aaron Mazie\log does not exist.

I am on Windows 10 and running the latest versions. (Node.js 9.11.1 and NPM 5.6.0). Any help would be super appreciated.

num8er
  • 18,604
  • 3
  • 43
  • 57
Aaron Mazie
  • 763
  • 6
  • 15
  • Have you tried reinstalling the package? It usually fixes things. – Ivan Apr 15 '18 at 00:35
  • execute: `forever logs 0` and see errors that cause issue. – num8er Apr 15 '18 at 00:35
  • Try this way: `forever start -c "node -r babel-register" app.js` – num8er Apr 16 '18 at 12:24
  • I tried it and it still says the app is stopped – Aaron Mazie Apr 16 '18 at 14:28
  • add app.js file to Your question – num8er Apr 16 '18 at 15:11
  • According to the first sentence of your question you're trying to start `app.py` not app.js -- can that be the problem? If not, forever could run the wrong version of node.js (wrong nvm?) as per https://stackoverflow.com/questions/37634198/node-error-syntaxerror-unexpected-token-import – Gyuri Apr 16 '18 at 16:13
  • @Gyuri It used to work before. – Aaron Mazie Apr 16 '18 at 21:26
  • @Gyuri surprisingly Aaron is right. Nodejs module `forever` can execute any code if You use `-c "interpreter code-file.ext"`. But it's funny to see non nodejs world do this trick ))) – num8er Apr 17 '18 at 17:42
  • @num8er turns out I was also right: a Python script was attempted to be run as javascript -- thus the `Unexpected token import` error. ;) – Gyuri May 10 '18 at 22:01
  • @Gyuri off course. If You don't pass custom command it calls nodejs and yes it parses it as JS code – num8er May 11 '18 at 03:45

1 Answers1

1

Fix Your issue by checking logs.

Execute in terminal:

1) forever list and find Your app is running

$ forever list
info:    Forever processes running
data:        uid      command             script    forever pid   id logfile                         uptime        
data:    [0] UID-HERE /usr/local/bin/node app.js 63123   56557    /home/api/.forever/UID-HERE.log STOPPED

2) forever logs 0 (0 for [0] sequential number in listing)
or
forever logs 0 -f (for continuous reading)

3) Read logs and fix Your issue

I can guess that it may be EADDRINUSE because of port conflict when You run many apps using same port, so if Yes:

make sure that there is no same app.js in listing (forever list)

or

execute: ps -ax | grep node and see nodejs apps possibly running by maybe other users on system

UPDATE:

Since You're running python script using nodejs module (forever), try to run it like that:

forever start -c "python app.py"
num8er
  • 18,604
  • 3
  • 43
  • 57
  • I checked and port usage was not the issue. I edited my post and included the error message above – Aaron Mazie Apr 15 '18 at 22:51
  • @AaronMazie seems like You're using Babel in local development, so to run it using forever transpile Your code to usable node code and run it with forever. Or search: `run node babel with forever` in Google – num8er Apr 16 '18 at 04:38
  • The app I'm running is actually in Python, which is what I'm familiar with. Also, is Babel something that comes with Node.JS because I didn't download that seperately? – Aaron Mazie Apr 16 '18 at 14:25
  • @AaronMazie You've set tags in Your question: `node.js` and `forever` and You wrote that error says `Unexpected token import` that means in some part of Your code use such line: `import SomePackage from 'some-library'` that is not supported natively by nodejs and it's being converted using transpilers (babel). But now You're saying that You use Python? How come? Whaaat (: Can You share `app.js` file in Your question? – num8er Apr 16 '18 at 15:09
  • I'm using forever to run a Python script perpetually. It crashes sometimes because of lag errors from the API I'm calling, so I use forever to keep it up. Could the transpiler errors be from my Visual Studio, GCC/G++ compiler? I had updated it. I use both Cython and Python. I've tried both types of scripts with forever and it's the same – Aaron Mazie Apr 16 '18 at 16:04
  • @AaronMazie added example running python script via forever, look at the end of my answer. – num8er Apr 17 '18 at 17:34
  • 1
    YOU ROCK! It works. Thank you so much for continuing to try to help me. SO appreciated. And I apologize for assuming that app.js and app.py would be the same thing. Used to work the other way before, I don't know what changed. Anyway, thanks so much again – Aaron Mazie Apr 17 '18 at 18:17
  • @AaronMazie no need to apologise) it happens with anyone. glad that it worked. – num8er Apr 17 '18 at 19:18