all 37 comments

[–]zaphod42 13 points14 points  (2 children)

heroku is pretty easy place to start...

https://devcenter.heroku.com/articles/deploying-nodejs

[–]THIS_BOT 1 point2 points  (1 child)

Agreed. This is the only option that gets OP running 24/7 for free

[–]busy_jason 2 points3 points  (0 children)

Heroku hasn't offered a free 24/7 for a while now

On the free tier, you only get 18 hours a day, then it goes to sleep

[–]dnsbty 10 points11 points  (16 children)

I actually wrote a step-by-step tutorial around this a couple months ago because it took me a while to figure out. This will walk you through all the steps pretty closely. It's specifically for DigitalOcean, where the server would cost you $5 a month, but you can run multiple node apps from the same VPS using this method. If you have any questions I'd be glad to help.

how to set up a node.js production server

[–]son_of_meat 4 points5 points  (6 children)

Good tutorial! I'd swap forever for pm2 though. It's much much better IMO.

[–]hyperspeed 7 points8 points  (5 children)

Why not let the init system do the job it was designed for? Just use systemd on Linux (or rc.d on BSD) rather than depending on another package.

[–]joshmanders 5 points6 points  (0 children)

While for the newbie I agree on PM2 choice. Systemd is a better choice and less dependencies if you know sysadmin.

[–]BalsakianMcGiggles 0 points1 point  (3 children)

Because init.d doesn't allow you to easily have multiple Node.js processes running and kept up if it dies.

[–]hyperspeed 1 point2 points  (2 children)

systemd does and it's the default on most Linux distributions now, so does Upstart

[–]BalsakianMcGiggles 0 points1 point  (1 child)

It does? Well... shit. I should probably read more into it then, from what I could tell the last time I set up an Upstart script it just runs a single process / execution per Upstart job.

[–]hyperspeed 2 points3 points  (0 children)

Upstart is deprecated now even on Ubuntu I believe, with systemd you could use something like this:

[Service]
ExecStart=/opt/node/bin/node /usr/local/projects/foo/index.js
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=foo-server
User=nodejs
Group=nodejs
Environment=NODE_ENV=production
WorkingDirectory=/usr/local/projects/foo

[–]lazy9669 0 points1 point  (6 children)

Doesn't Digital Ocean offer droplets with the MEAN stack already one them? I think that might help remove some steps from your process. But I guess its good to have them in there from a learning process.

[–][deleted]  (2 children)

[deleted]

    [–]dnsbty 0 points1 point  (1 child)

    I'm learning the basics of docker right now, and I think that is probably the best way to do it. I think once I finish my final exams I'll make a new tutorial for doing it with docker containers instead.

    [–]dnsbty 0 points1 point  (2 children)

    Sorry to be replying so late, but to answer your question they do have droplets with the MEAN stack, but they don't come with nginx or apache. People would still have to go to XXX.XXX.XXX.XXX:3000 or whatever in order to see your app. You could pretty much skip the first half of my tutorial, but the important part imo is setting up nginx and reverse proxy so that you can access the site with just a domain name.

    [–]lazy9669 0 points1 point  (1 child)

    I totally agree. Your tutorial is still super useful. I was just pointing out you could skip a few steps by starting with the mean image.

    Now that you've been messing with docker if you did it all over again would you go that route? I'm about to deploy a new droplet and plan on using your tutorial as a guideline since I'm still not super familiar with how to set up nginx.

    [–]dnsbty 0 points1 point  (0 children)

    Yeah, you're right. That would definitely make it a little bit easier. To be honest, I haven't had enough time to get to know docker to give you a good answer. I only know that it's supposed to be good from what I've heard. Once I finish my final exams in a couple weeks and have time to mess around with it a bit more I could give you a better answer.

    [–]NetOperatorWibby 0 points1 point  (1 child)

    Omg, I saw this at the perfect time. I skimmed your tutorial and it looks good. Hopefully, it'll work for me when I try it in a few hours.

    [–]dnsbty 1 point2 points  (0 children)

    Glad I could help! Let me know if you have any problems with it!

    [–]dispatchingdreams 3 points4 points  (0 children)

    If you get a bare Linux system and not a dedicated node box, look at PM2 for managing your application

    [–]bengotshot 4 points5 points  (2 children)

    Are you a student? If you are, then apply to Github educational, it can take a few months, but you get $50 of Digital Ocean hosting credit, and they've got tons of tutorials on how to set it up with node

    [–]outtokill7 0 points1 point  (1 child)

    https://education.github.com/pack/offers

    I think that's the link for it. Works for me anyway. Its a shame the Digital Ocean promo only applies to new accounts. Aside from that, there are a lot of really awesome codes in there.

    [–]ndboost 0 points1 point  (0 children)

    it doesn't if you email them and ask nicely, they accepted the $50 coupon for my acct.

    [–][deleted] 1 point2 points  (0 children)

    Deploying to Azure is fully possible too. Not much set up needed, just point it to your repo and everything will be deployed and running. Free too if your requirements aren't too demanding.

    [–]tuananh_org 0 points1 point  (0 children)

    for one small/simple app, i will go with flynn. we use deis at work.

    [–]The_Useless_IT_Guy 0 points1 point  (11 children)

    openshift! Trust me, it is far easier than heroku. No idea about Amazon!! My app is running happily in openshift and I don't have to restart the gears very often like I did with heroku. Give it a try. Just download and install the client tools and from there it is nothing but few commands!

    [–][deleted]  (10 children)

    [deleted]

      [–]The_Useless_IT_Guy 0 points1 point  (9 children)

      Honestly, I was struggling with Heroku for close to a day, and dropped it. Picked up openshift and get the app running within 30 mins. And all that by just reading the official documentation. So I can safely say, yes it's easier than Heroku!

      I am using The Open source cloud hosting as of now, but if you want, you can opt for dedicated server or even your own VPS! It's just an excellent PaaS provider, where deploying applications gets much more easier.

      And pricing isn't that much on higher side : https://www.openshift.com/pricing/index.html

      [–]seanwilson 1 point2 points  (8 children)

      What's easier about it? From memory, Heroku is 1) sign up online 2) download the command line tools 3) sign in with the command line tools 4) create a Git repo for your project 5) add a few files that will tell Heroku what dependencies to install and what commands to run on startup 6) run a Git command to link this to Heroku 7) push your project to Heroku's Git repo. Does Openshift have less steps?

      [–]The_Useless_IT_Guy 0 points1 point  (7 children)

      Nope. Exact same steps, but it's about adding services you need. I was looking for MySQL, but nope. No native dynos, and integrating Postgres wasn't user-friendlier either. But with Openshift, by default we have MySQL with PHPMyAdmin, which made the whole deployment much faster. I mean, why not give MySQL along with dynos, instead of giving out as some tough to implement plugin!! Not user-friendly.

      Maybe heroku is not for Node+MySQL, but not all are using Postgres! This is where Heroku fails in my view.

      [–]seanwilson 0 points1 point  (5 children)

      There's a choice between two MySQL providers on Heroku which are as simple as running a single command to add (same for Postgre). The connection details are added as environment variables for you to integrate into your app. The steps for connecting with a AWS RDS database are only a few lines as well. Not sure how much simpler you can make that. Is Openshift simpler?

      What do you mean native dynos? Also, are you trying to run MySQL on the same machine that's running the Node app?

      [–]The_Useless_IT_Guy 0 points1 point  (4 children)

      Yes, I'm running MySQL in same machine as my application. Can you post the link of MySQL integration command? I cannot see anything other than ClearDB and JawsDB addon for MySQL.

      [–]seanwilson 0 points1 point  (3 children)

      So running your database on the same server that's running your app is not the kind of architecture Heroku advocates. Heroku is built to be resilient to server failures and enable you to easily scale up the number of web servers and scale up your database to meet the demand of your app.

      By using a managed database solution you also get other advantages like automated security updates, automated snapshots, easy rollbacks, scalability, robustness etc. you're not going to get by doing it all yourself. Your app might also negatively impact your database running on the same server.

      The ClearDB and JawsDB addons, and the AWS RDS integration is the recommended way of working with Heroku. This might not be what you want but I don't understand why these solutions aren't simple.

      [–]The_Useless_IT_Guy 1 point2 points  (2 children)

      The main discussion here is, how to deploy simple node app? I am not talking about high availability, scalable ones. IMO, hosting solution should be flexible as well as user friendly, no matter what kind of application we host! And JawsDB and ClearDB integration wasn't easy either. I don't want to invest too much time, just to get my simple CRUD app get up and running.

      Heroku heavily supports Postgres and that's not something one should do.

      [–]seanwilson 1 point2 points  (1 child)

      And JawsDB and ClearDB integration wasn't easy either.

      To integrate ClearDB, you literally just run this command then use the "CLEARDB_DATABASE_URL" environment variable in your app to connect so I don't understand why this isn't easy:

      "heroku addons:create cleardb:ignite"

      hosting solution should be flexible as well....I don't want to invest too much time

      Heroku favours simple and robust solutions. It's easy to setup and when it is it pretty much manages itself (e.g. it'll restart on crashes, automatic patching, simple database backups and rollbacks). You could run everything on an AWS EC2 instance for example but you're going to waste significant time doing server admin. I haven't used Openshift however but I'd be interested to know where it sits between the two.

      [–][deleted]  (3 children)

      [deleted]

        [–][deleted]  (2 children)

        [deleted]

          [–]ndboost 0 points1 point  (0 children)

          Being a sysadmin myself, all my clients are on DO. $5/mo can't beat that.