Running a node.js app with upstart and Procfile - node.js

I have a node.js application.
I have written a Procfile with the following contents.
subscription-engine-processor: node index.js
Not sure whether i am doing it right, but i tried running it with the ruby gem foreman.
$ foreman start
nothing happens. The process doesn't run.
Please do comment on whether i am doing it right, if there's any other way of running this is my local. What i ultimately want to do is to export this using upstart when its finally deployed in production.

I'm not exactly sure what foreman does, but I can give you the following links so that you can read more in depth tutorials on how to setup Node with Upstart:
http://howtonode.org/deploying-node-upstart-monit
http://caolanmcmahon.com/posts/deploying_node_js_with_upstart
http://dailyjs.com/2010/03/15/hosting-nodejs-apps/
http://blog.clock.co.uk/2011/04/11/deploying-node-js-apps/
Hope these help.

You might need this https://github.com/strongloop/node-foreman its a node port of foreman.

Related

Why does PM2 work on one server, but not on another?

We have two instances of our Node-Express app: one for development, and one for production. We are implementing PM2 process manager. This is for a Windows Server 2012 environment.
For some baffling reason, PM2 (with pm2-windows-service) worked fine when set up in our dev environment, but won't even run node in our Prod environment. What could be the cause?
Log files reveal nothing helpful
If you look at my related question, you can see that PM2 appears to be launching node, but is not (or it instantly crashes).
All we can conclude is there is some difference in settings between these two servers. Any clue what difference in settings might be causing PM2 to fail like this?
This is related to a more specific question I have out there about issues we're having implementing PM2.
Thank you!
Ok, I got the answer after posting an issue to the pm2 github issues page.
Sharing it here in case anyone else finds themselves in this situation:
https://github.com/Unitech/pm2/issues/4113
(basically pm2 3.2.5 introduced a bug that causes this issue in Windows. My QA install was 3.2.4. The issue was resolved by reverting to 3.2.4. Simple process, see instructions at link above.)
It may be not really pm2 issue, bit more npm. On the server where pm2 doesn't work please try that command in PowerShell:
Get-Command pm2
Does it return the correct version(not 0.0.0)? If not, there is an issue diring installing that package, so as an option it's possible to install that manually. Also we asked familiar question in that ticket last month:
https://github.com/Unitech/pm2/issues/3964
Like it described in a ticket above you can try to check other npm package with familiar issues:
npm install mocha -g
And that try to reach mocha-cli

Heroku cannot find ./node_modules/.bin/forever in Procfile of Yeoman MEAN app

I've been trying to get a Yeoman generated MEAN.js app deployed to Heroku for the best part of a day without much luck.
I've carefully gone through all the steps and am pretty sure I've done everything correctly according to documentation.
After several times going through and ensuring the database is configured correctly with heroku config, removing the public/dist folder from the .gitignore, running grunt build, setting NODE_ENV=production, and running a successful Heroku build the app just continuously shows the very unhelpful Heroku Application Error page.
Upon checking the heroku logs the only thing I can find is this:
bash: ./node_modules/.bin/forever: No such file or directory
Process exited with status 127
Which clearly refers to the Procfile that contains this single line and is where the app is supposed to start from.
web: ./node_modules/.bin/forever -m 5 server.js
There is a server.jsin the root of the project so I tried modifying the Procfile to a standard web: node server.js but that doesn't fix it and I am not comfortable messing with the default Yeoman configuration.
The ./node_modules/.bin/forever is of course there where it is supposed to be. But it obviously isn't showing up or cannot be located in the live Heroku build. If anyone knows what the problem is here and how to fix it I'd much appreciate the help! Cheers!
This happened to me after I upgraded my nodejs, I can't figure out why exactly it is happening, but here is my fix for it asap,
When I ran heroku run ls node_modules/.bin/
I could not find forever there. So I installed and save it to my dependencies by running npm install forever --save
On running heroku run ls node_modules/.bin/ again, it was there and my app runs fine.
I'll sure update this soon, once I figure what exactly led to it.

Steps to Deploy Express React Redux template to Heroku

Limited experience with Node and deploying to Heroku. I've built something up using this boilerplate: https://github.com/DimitriMikadze/express-react-redux-starter but am not really certain how to set up the template for deployment to Heroku.
Any basic steps would be super helpful. Thank you!
Heroku's docs are actually really great! https://devcenter.heroku.com/articles/getting-started-with-nodejs . That will walk you through deploying their example repo, but the starter kit you linked to above will work almost exactly the same. I would walk through that tutorial to deploy Heroku's example repo first just to make sure you have their toolkit properly installed and generally understand how it works, it won't take long at all. Then I would move on to deploying the app you've built. The one change I know you'll have to make is what you put in your Procfile. Yours will need to look something like this:
web: npm run build && npm start
hope that helps!
The Heroku + NodeJS getting started tutorial was incredibly helpful. After fiddling around with deploying to Heroku I realized my problems were as following:
pm2 dependency -- as suggested I removed it and replace the npm start script to just PORT=8080 node start ./server.js
However, that caused separate problems:
A. 'start' was undefined, B. I got a Heroku error "web-process-failed-to-bind-to-port", and C. missing Webpack + other dependencies
By simply removing the hardcoded port and "start" -- so the script is now just node ./server.js as well as fixing any devDependencies AND setting my Heroku config to NPM_CONFIG_PRODUCTION: false it works now! Huzzah. Thanks for the assistance on this.

heroku running gulp build

i am trying to install a node app onto heroku. My application requires both gulp build and gulp install to be called on the server upon instillation, however i am having troubles doing this.
I have tried writing this inside of the package.json:
"scripts":"gulp build && gulp install"
which works at first, but after about an hour the server must restart and recall the script causing for the contents of the server to be rebuilt. this removes all of my content such as newly written blogs or changes.
I have also tried using the heroku toolbelt
heroku run gulp build
heroku run gulp install
However, even though it produces the correct console write lines and looks asif it has made the necessary changes, it hasn't, the server produces an error which proves that the resources haven't been built meaning that the console command didnt make any changes to the actual server files.
Am i missing something out here? Thanks in advance.
So i have figured out that the problem lies with the fact that i have tried to use a LevelDB database on heroku. Apparently, heroku uses no-writable dynos, meaning that the levelDB database is unable to save.

How to edit and deploy code without restarting server?

I have node server which i run using forever. But each time if I edit my code I'll have to restart the server. I came across the module called hotnode which can perform live edits but will it have the same performance as the forever module or can I run my code using both the modules. I am confused. Any help wil be much helpful
Have a look at nodemon.
nodemon will watch the files in the directory that nodemon was started, and if they change, it will automatically restart your node application.
As an alternative to nodemon you can use node-supervisor.
I used to use nodemon, but for some reason it didn't detect code changes on my linux box, which supervisor did flawlessly.
The downside is that it doesn't (or at least didn't) give the colorful output nodemon gives.

Resources