Using forever command to run node.js script on heroku - javascript

So, I searched a lot before asking this here as I was not able to find a single answer related to this small problem.
I want to run node.js file on my heroku server which is on free-tier but I don't want to use node file.js. I want to use forever start file.js.
So, I did wrote the commands in my package files as well as defined a Procfile for worker: forever start file.js.
And deployed to heroku, but all the logs says that
forever: bash command not found.
Any solution ?

Related

Node js server auto restart [duplicate]

I am running a node.js application in Windows and I want to make it automatically restart if there is an unhandled exception in the code which causes the application to stop.
I have done some research and I found that a combination "Forever" and "Nodemon" can achieve this goal.
I installed both packages globally on my Windows 10 Device.
npm install forever -g
npm install -g nodemon
I tried using the following command to launch my app:
forever start nodemon --exitcrash app.js
However, I get the following error: "nodemon does not exist"
If try just running "nodemon" the application starts which indicates the Nodemon package is installed however, this will not allow the app to restart after a crash.
Am I doing something wrong? Most advice I find online is only relevant to Linux systems.
If you are already using forever, then you can get rid of nodemon. Instead you can use a combination of forever and cluster module. Simply fork the worker in case of exceptions, and it makes your app more scalable too!
If still nodemon is preferable, maybe try installing it globally using the -g flag
Forever and nodemon achieve 2 completely different objectives
nodemon is used to run your application in development mode, where you are frequently changing code, and need to restart the server .It will not restart your application in case of a crash. more about that later
Forever, on the other hand, is for making your application run as a daemon in production. And auto restart if you have uncaught exceptions.
Historically people have used Forever stand alone, or with upstart scripts, running as a linux service one of the most famous being upstart
Current norm is to use PM2

Deploy Javascript Cron Jobs and Queues on Amazon Elastic Beanstalkd

I have an Amazon Elastic Beanstalk application currently running my NODE.JS app.
I have created some Queues with kue.js and Crons with node-schedule.
Since I have many commands to run the queues and crons, I find it impossible to put it on my current nodejs app.
I am willing to open a new application, the only problem is that I can only run one command.
I really don't want to open a seperate ec2 (not connected to my Elastic Beanstalk service) to run all of those.
What can I do to fix it?
Thank you very much!
As you want to use EB(Elastic Beanstalk) you could write a docker file for the application and EB will already detect that and ask you if this is a docker based project and it will take care of the rest, you just need write all the scripts that you need to run before your Entry point Command CMDnpm start like below
Dockerfile
FROM node:10.13-alpine
# Sets the working directory,and creates the directory as well.
WORKDIR /app
# Install dependencies.
ADD package.json .
RUN npm install
# Copy your source code.
COPY . /app
#Run all your scripts here or simply put them to a scripts.js and run it
RUN node scripts.js
# start app
CMD ["npm", "start"]

How do I run a copied project in Node.js

https://github.com/gleitz/mahjong
I want to run this app on my windows,
the directions say:
-Install dependencies with npm update
-Start the application with node app.js
it's sound easy so I try myself.
1.Fist of all , I install node.js on it's official website (https://nodejs.org/en/)
I download the 8.9.3 version.
after installing node.js
2.open the command line and go to the project path.
3.then I input the command npm update.
it works,and the node_modules folder is created.But there are some warn message
4.finally input the command node app.js... it's not work with many error message
following is wrong message
I wonder know how should I do.Is any thing I didn't installed?
Please help me.I really want to research this mahjong project.
Before running npm update in the directory where you have your project, you should run npm install first to install all the required dependencies needed for the project to run.
So I advice to delete the node_modules directory that was created after you ran npm update, after which you can then run npm install. This should solve your issue.
Update: If you just want to try it online and not run it locally they've hosted a version on the web: http://gleitzman.com/apps/mahjong.
It's not your fault.
What you did was correct, but the project documentation needs to be updated. It's not a turn-key solution and you'll need to figure a few things out to get it working.
The error message is says it wants a mongo db instance, but you don't have one running. Try the mongodb home page or google for instructions. If you have docker it is pretty easy: docker run -it -p 27017:27017 mongo.
Even after spinning up mongodb I wasn't able to get the app to work locally. You could try contacting the repo maintainer for assistance. They may be happy to help given you've shown interest in their project.
Good Luck!

Cannot run express with node on Heroku

I've deployed my app on Heroku and I have an express script that should wait for a post request. I need to run it separately on Heroku. When I open the console on Heroku and type:
heroku run bash node scripts/start_express.js
I get the following error:
/app/.heroku/node/bin/node: /app/.heroku/node/bin/node: cannot execute binary file
How do I use node to run my js file on Heroku?
The node buildpack for heroku will automatically look for npm start script in your package.json file. That is where you can specify which file to serve up. Check this article out for some help on node and heroku https://devcenter.heroku.com/articles/nodejs-support

Setup node.js App for pubblication with PM2

I have a node.js application that uses the python-shell module. When I start the app with the command: node server.js everything works well, including Python scripts. If I try to start the application with the pm2 start logs server command, Python scripts do not work and I get a lot of errors on PythonShell, Object.callPythonScript.
Does anyone know how to fix and how does the application normally work with the node compiler, but not with pm2?
This is the logs error:

Categories

Resources