Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js forever cannot start script

Tags:

node.js

I have a node.js script on my server that I want to run continuously even after I logout of SSH. I decided to use forever for this.

Problem: When I try to start the node.js script using forever start app.js, I get the following error. Is there more configuration that is required?

The "sys" module is now called "util". It should have a similar interface.
info:   Forever processing file: app.js
{
  "process": {
    "pid": 24257,
    "uid": 0,
    "gid": 0,
    "cwd": "/home/node/nodejs",
    "execPath": "/usr/local/bin/node",
    "version": "v0.6.2",
    "argv": [
      "node",
      "/usr/local/bin/forever",
      "start",
      "app.js"
    ],
    "memoryUsage": {
      "rss": 13729792,
      "heapTotal": 8367232,
      "heapUsed": 5130572
    }
  },
  "os": {
    "loadavg": [
      0.02734375,
      0.0322265625,
      0.0009765625
    ],
    "uptime": 1474229.393550878
  },
  "trace": [
    {
      "column": 21,
      "file": "/usr/local/lib/node_modules/forever/lib/forever/cli.js",
      "function": "getOptions",
      "line": 172,
      "method": null,
      "native": false
    },
    {
      "column": 17,
      "file": "/usr/local/lib/node_modules/forever/lib/forever/cli.js",
      "function": "",
      "line": 210,
      "method": null,
      "native": false
    },
    {
      "column": 19,
      "file": "/usr/local/lib/node_modules/forever/node_modules/flatiron/node_modules/director/lib/director/router.js",
      "function": "apply",
      "line": 355,
      "method": null,
      "native": false
    },
    {
      "column": 9,
      "file": "/usr/local/lib/node_modules/forever/node_modules/flatiron/node_modules/director/lib/director/router.js",
      "function": "_every",
      "line": 28,
      "method": null,
      "native": false
    },
    {
      "column": 16,
      "file": "/usr/local/lib/node_modules/forever/node_modules/flatiron/node_modules/director/lib/director/router.js",
      "function": "apply",
      "line": 352,
      "method": null,
      "native": false
    },
    {
      "column": 9,
      "file": "/usr/local/lib/node_modules/forever/node_modules/flatiron/node_modules/director/lib/director/router.js",
      "function": "_every",
      "line": 28,
      "method": null,
      "native": false
    },
    {
      "column": 5,
      "file": "Object].invoke (/usr/local/lib/node_modules/forever/node_modules/flatiron/node_modules/director/lib/director/router.js",
      "function": "[object",
      "line": 350,
      "method": null,
      "native": false
    },
    {
      "column": 8,
      "file": "Object].dispatch (/usr/local/lib/node_modules/forever/node_modules/flatiron/node_modules/director/lib/director/cli.js",
      "function": "[object",
      "line": 67,
      "method": null,
      "native": false
    },
    {
      "column": 21,
      "file": "Object].start (/usr/local/lib/node_modules/forever/node_modules/flatiron/lib/flatiron/plugins/cli.js",
      "function": "[object",
      "line": 52,
      "method": null,
      "native": false
    },
    {
      "column": 9,
      "file": "/usr/local/lib/node_modules/forever/lib/forever/cli.js",
      "function": null,
      "line": 470,
      "method": null,
      "native": false
    }
  ],
  "stack": [
    "TypeError: Cannot call method 'reset' of undefined",
    "    at getOptions (/usr/local/lib/node_modules/forever/lib/forever/cli.js:172:21)",
    "    at Object.<anonymous> (/usr/local/lib/node_modules/forever/lib/forever/cli.js:210:17)",
    "    at apply (/usr/local/lib/node_modules/forever/node_modules/flatiron/node_modules/director/lib/director/router.js:355:19)",
    "    at _every (/usr/local/lib/node_modules/forever/node_modules/flatiron/node_modules/director/lib/director/router.js:28:9)",
    "    at apply (/usr/local/lib/node_modules/forever/node_modules/flatiron/node_modules/director/lib/director/router.js:352:16)",
    "    at _every (/usr/local/lib/node_modules/forever/node_modules/flatiron/node_modules/director/lib/director/router.js:28:9)",
    "    at [object Object].invoke (/usr/local/lib/node_modules/forever/node_modules/flatiron/node_modules/director/lib/director/router.js:350:5)",
    "    at [object Object].dispatch (/usr/local/lib/node_modules/forever/node_modules/flatiron/node_modules/director/lib/director/cli.js:67:8)",
    "    at [object Object].start (/usr/local/lib/node_modules/forever/node_modules/flatiron/lib/flatiron/plugins/cli.js:52:21)",
    "    at /usr/local/lib/node_modules/forever/lib/forever/cli.js:470:9"
  ],
  "level": "error",
  "message": "uncaughtException"
}

Additional Info

When installing forever using npm install forever -g, I get the following warnings, wonder if its relevant to the problem...

npm WARN [email protected] package.json: 'contributers' should probably be 'contributors'
npm WARN [email protected] package.json: bugs['web'] should probably be bugs['url']
like image 965
Nyxynyx Avatar asked Nov 30 '11 02:11

Nyxynyx


People also ask

How do I start npm forever?

What is npm forever? Forever is an npm package used to keep your script running continuously in the background. It's a handy CLI tool that helps you to manage your application in the development and production stages. To start running a script with forever, use the forever start command, followed by the script name.

What is forever in node JS?

What is forever? Forever is an npm module that ensures a Node. js script continuously runs in the background on the server. It's a helpful CLI tool for the production environment because it helps manage the Node applications and their processes.

How do I start a node js script?

The usual way to run a Node. js program is to run the globally available node command (once you install Node. js) and pass the name of the file you want to execute. While running the command, make sure you are in the same directory which contains the app.


2 Answers

I've solved the problem, it was bug in last release and they didn't upload to production, so install directly from git:

use npm install git://github.com/nodejitsu/forever.git -g

for details see the issue: https://github.com/nodejitsu/forever/issues/179

like image 64
Mikhail.Mamaev Avatar answered Oct 06 '22 06:10

Mikhail.Mamaev


To run process at the back end

$ nohup node simple-server.js > output.log &

The purpose of Forever is to keep a child process (such as your node.js web server) running continuously and automatically restart it when it exits unexpectedly. It's worth mentioning that there are other tools written to accomplish this task in a more generic way for any program or programming language:

Monit: http://mmonit.com/monit/
Upstart: http://upstart.ubuntu.com/
Daemontools: http://cr.yp.to/daemontools.html
Launchtool: http://people.debian.org/~enrico/launchtool.html

like image 38
Wazy Avatar answered Oct 06 '22 05:10

Wazy