I want to use -e and -o flags with pm2 to customize logs.
I tried:
pm2 start index.js -e="err.log" -o="out.log"
pm2 start index.js -e "err.log" -o "out.log"
pm2 start index.js --error="err.log" --output="out.log"
pm2 start index.js --error "err.log" --output "out.log"
Have anyone tried this? Any of those options doesn't work for me.
Related
The command docker-compose up --build will output build process and options like --quiet, --quiet-pull or --log-level ERROR won't work.
I also didn't find any other options in the documents.
Any help is appreciated.
If you are on linux:
docker-compose up --build 2>&1 1>/dev/null
If you are on Windows:
docker-compose up --build > nul 2> nul
I am getting this error in my Node.js console:
[nodemon] Internal watch failed: watch /home/dell/Downloads/Adaani5.0
(copy).0/node_modules/engine.io/index.js ENOSPC
For it, I have run two commands after an Internet search:
First:
ps -ef | grep node
sudo kill -9
Second:
echo fs.inotify.max_user_watches=582222 | sudo tee --append
/etc/sysctl.conf&& sudo sysctl -p
And the error persists.
sudo nodemon
Resolved for me. Or login to Root user.
I have a .sh script in my /etc/init-d/forever to configure how forever starts and stops my Node.js app.
I wanted to start forever with the command npm start, so I can trigger my scripts from there. Is this possible?
I tried
sudo forever start --sourceDir /home/my-app -c npm start
but its gets wrong interpreted...
info: Forever processing file: start
error: Cannot start forever
error: script /root/start does not exist.
My script so far is:
NAME=nodeapp
SOUREC_DIR=/home/nodeapp
COMMAND="npm start"
SOURCE_NAME=index.js
USER=root
NODE_ENVIROMENT=production
pidfile=/var/run/$NAME.pid
logfile=/var/log/$NAME.log
forever=forever
start() {
export NODE_ENV=$NODE_ENVIROMENT
echo "Starting $NAME node instance : "
touch $logfile
chown $USER $logfile
touch $pidfile
chown $USER $pidfile
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
sudo -H -u $USER $forever start --pidFile $pidfile -l $logfile -a --sourceDir $SOUREC_DIR -c $COMMAND
RETVAL=$?
}
So I found the answer.
Both --sourceDir and the path parameter after the "npm start"command where necessary:
sudo forever --sourceDir /home/my-app -c "npm start" /
The below command run the forever command in the background with logs in forever.
forever start -c "ng serve " ./
Note the ./
Then you can
forever list
And will be able to see the status and the location of the log file.
info: Forever processes running
data: uid command script forever pid id logfile uptime
data: [0] wOj1 ng serve 29500 24978 /home/user/.forever/wOj1.log 0:0:25:23.326
I am running into an issue. I have deployed my nodejs websocket app to Amazon elastic beanstalk. I am trying to run app as daemon process, that's why I have globally installed pm2 using configfile in ebextension:
container_commands:
01_node_symlink:
command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/node /bin/node"
02_npm_symlink:
command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/npm /bin/npm"
03_pm2_install:
command: "if [ ! -e /bin/pm2 ]; then npm install pm2 -g; fi"
ignoreErrors: true
As elastic beanstalk start server automatically, to use pm2 I have written start command in my package.js
start:"pm2 start server.js -i 0 --name="hub""
But when elastic beanstalk uses this command to start server it goes in start-stop loop and all cpus is used.
Thanks in advance
That's because pm2 process exits just after it starts the server, so eb run it again. add " && pm2 logs" to the command to keep it on.
My package.json has:
"scripts": {
"start": "node_modules/.bin/coffee server.coffee",
"test": "NODE_ENV=test node test/runner.js",
"coverage": "NODE_ENV=test COVERAGE=1 node test/runner.js -R html-cov test/ > ./test/coverage.html",
"testw": "fswatch -o test src | xargs -n1 -I{} sh -c 'coffeelint src server.coffee ; npm test'",
"db:drop": "node scripts/drop-tables.js",
"encryptConfig": "node_modules/.bin/coffee config/encrypt.coffee",
"decryptConfig": "node_modules/.bin/coffee config/decrypt.coffee",
"postinstall": "npm run decryptConfig"
},
When I deploy to Elastic Beanstalk, I'd like to run the postinstall, but apparently it doesn't do that. Okay, no problem.
I created a file called .ebextensions/00.decrypt.config which has:
commands:
00-add-home-variable:
command: sed -i 's/function error_exit/export HOME=\/root\n\nfunction error_exit/' /opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh
container_commands:
02-decrypt-config:
command: $NODE_HOME/bin/npm run decryptConfig
However this doesn't seem to run either. What am I doing incorrectly?
I figured out a workaround for this issue. The npm binary on an EB instance is located in /opt/elasticbeanstalk/node-install/node-{version}. You should make sure this is present in your PATH first.
00_setpath.config
commands:
01_set_path:
command: echo 'export PATH=$PATH:`ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin' >> /root/.bash_profile
02_set_path:
command: export PATH=$PATH:`ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin
As you can see I am appending to .bash_profile and also adding PATH to the current shell. The former should be sufficient for your purpose. I added the second one as I'm using the npm command within a script in my package.json, and it seems these scripts are run inside the same shell. TL/DR: You should now be able to use npm in both places.
As for your npm scripts, try using prestart instead of postinstall.
A few suggestions:
Try to enclose your commands in quotes, that's a requirement
Also, not sure if $NODE_HOME is working - could you run simple test like echo $NODE_HOME > /tmp/test.txt?