Running npm global package as service with forever - node.js

I am trying to run my own instance of the discord bot available here: https://github.com/Gawdl3y/discord-rpbot. I have a Windows server VM set up and installed the script as a global npm package, and it definitely works because I can get the bot running correctly by simply executing
rpbot --token [token]
I would like to have this run in the background with forever (https://www.npmjs.com/package/forever) -- however, when I try to execute it with the command
forever AppData/Roaming/npm/rpbot --token [token]
it crashes with the following error:
warn: --minUptime not set. Defaulting to: 1000ms
warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
C:\Users\myusername\AppData\Roaming\npm\rpbot:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
^^^^^^^
SyntaxError: missing ) after argument list
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)
error: Forever detected script exited with code: 1
I assume I'm not using forever correctly for executing a globally available command like this, but all the documentation I've been able to find is mum on the subject. Any help for how to make this work would be appreciated!

Related

How to schedule an adonisjs command with plesk scheduler?

I have this created command called 'newsletter'. When I call 'adonis newsletter' on local, it works just fine. But when I try to run with scheduler on plesk with 'cd httpdocs; node ace newsletter', it was completed with this error:
/var/www/vhosts/mydomain.com/httpdocs/node_modules/#adonisjs/ignitor/src/Ignitor/index.js:286
async _bootProviders () {
^^^^^^^^^^^^^^
SyntaxError: Unexpected identifier
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:44...
anyone know what is wrong? when i tried 'cd httpdocs; adonis newsletter' it gaves error too, it said that command not found.. my node version is 14
It worked when I use this command :
cd httpdocs; /opt/plesk/node/v16.13.1/bin/node ace newsletter;

Composer Rest Server error "async *__getField() {"

I have followed this (https://medium.com/coinmonks/build-a-insurance-application-with-hyperledger-composer-and-react-js-part-1-3ebe7ad54986) tutorial upto "create our REST API".
Now when i run following command
composer-rest-server -c admin#secure-phi -n never -u true -w true
I get following error
/home/ali/.nvm/versions/node/v8.17.0/lib/node_modules/composer-rest-server/node_modules/formdata-node/lib/FormData.js:206
async *__getField() {
^
SyntaxError: Unexpected token *
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object. (/home/ali/.nvm/versions/node/v8.17.0/lib/node_modules/composer-rest-server/node_modules/#tim-lai/isomorphic-form-data/lib/index.js:2:18)
Is this a syntax related error or something else, and any way to fix this?
I found the error is related to generator not supported below node v8, but hyper-ledger-composer specifically requires node v8, so any work around to this?
It seems to be a version conflict between sub-dependencies in the graph.
Looks like the package 'g11n-pipeline' is requiring a different version of 'swagger-client' that pulls the dependency '#tim-lai/isomorphic-form-data'.
I did this workaround as it is a global package (we don't have access to the package-lock.json/package.json).
Since you've installed with NPM (npm i -g composer-rest-server):
cd /home/ali/.nvm/versions/node/v8.17.0/lib/node_modules/composer-rest-server
npm install swagger-client#3.9.0
rm -rf node_modules/g11n-pipeline/node_modules/swagger-client

Run a node package via node

I am trying to run a node package.
Technically, I can simply do ./node_modules/.bin/<package name> from my project's root folder, or even npx <package name> from any folder.
But I need to run node with a specific configuration of max-old-space-size set to 4096.
I am therefore trying to invoke it as follows:
node --max-old-space-size=4096 ./node_modules/.bin/<package name>
Which gives me the following error:
<root folder>\node_modules\.bin\<package name>:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
^^^^^^^
SyntaxError: missing ) after argument list
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:599:28)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
I am pretty sure that this problem is due to the fact that I am running on Windows.
I did some research and came across this GitHub thread, which makes me even more confident that the problem is OS-related.
But I haven't been quite able to find a workable solution within this thread.
The only clue that I have found is by sc0ttwad3 from 12 days ago, suggesting to change this:
./node_modules/.bin/<package name>
To this:
./node_modules/<package name>/bin/<package name>.js
But there is no such js file in this path (in fact, there is not even a bin folder in this path).
Can anyone shed some light on this?

Wit ai based node.js code on running with forever command throws error

I am trying to develop a facebook messenger bot application with the use of wit.ai framework. The application runs fine when i run my node.js code with command
node app.js
But when i try to run it with the use of forever command like below i am getting the following error in wit library file.
forever -o out.log -e err.log start app.js
string_decoder.js:66
var buflen = buffer.length;
^
TypeError: Cannot read property 'length' of null
at StringDecoder.write (string_decoder.js:66:22)
at Interface._normalWrite (readline.js:319:30)
at Interface.write (readline.js:310:49)
at message.converse.makeActionCallback.runActions.interactive.rl.on [as
interactive] (/home/user/example/lib/wit.js:289:13)
at Object. (/home/user/example/app.js:540:8) at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
Any help will be highly appreciated!!
I found a workaround for this which was suggested by someone else in github. In wit.js line 300 replace
this.rl.write(null, {ctrl: true, name: 'e'});
with
this.rl.write( '', {ctrl: true, name: 'e'});

How to set environment variables to get forever run meteorjs

How do you set the environment variables to get forever run meteorjs?
If I do an export and run forever, like so
export PORT=80 MONGO_URL=mongodb://localhost:3002/appname
sudo forever -f start bundle/main.js
forever will not run the meteorjs bundle with node:
/Users/../bundle/server/server.js:166
throw new Error("MONGO_URL must be set in environment");
^
Error: MONGO_URL must be set in environment
at run (/Users/../bundle/server/server.js:166:11)
at Object.<anonymous> (/Users/../bundle/server/server.js:331:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/../bundle/main.js:1:63)
at Module._compile (module.js:456:26)
error: Forever detected script exited with code: 8
If I run it directly, it runs smoothly:
sudo PORT=80 MONGO_URL=mongodb://localhost:3002/appname ROOT_URL=http://myapp.com node bundle/main.js
If I do it like in this answer it works. But why doesn't it work with the export statement?
Is there a way to tell forever a config file to read those settings? I don't see a way in the forever docs.
You can run forever just like node. Try following
sudo PORT=80 MONGO_URL=mongodb://localhost:3002/appname ROOT_URL=http://myapp.com forever -f start bundle/main.js

Resources