Although AWS now has its own PAAs platform called Elastic Beanstalk, the advantage of Heroku is that it has a number of third-party add-on, such as Mongodb,mysql, Redis, memcached, and various message queues, SMS and mail, background batch, search, automatic monitoring and other plug-ins, from an ecological perspective than AWS or much stronger.
That is to say, there is a ready-made node.js PAAs running environment on the Heroku, and a lot of add-on, which automatically backs up the data to AWS S3 every day, you just need to push the code up with Git commands, and nothing else. Is there a better thing in the world for us to program apes?
So, in order to benefit the netizen, I today put forward a few small steps of deployment summary.
Suppose you already have a node.js application called sample, the code is placed under/home/apps/sample9527, the directory has your server-side core JS file Server.js, now you have CD to this directory.
In order for Heroku to identify your application, you need to include a file Procfile in this directory, one line of code:
(The Web:node here is to tell Heroku that you are deploying a node.js Web application, and that the server.js is your server-side core program code file name)
Well, now the deployment can begin.
First, you need to register a user on the www.heroku.com, the username is your email address. Then install Heroku Toolbelt, which is a command-line tool that lets you publish code directly in the shell, view the system state, modify the server configuration, and so on.
Then log in with the Heroku login command in the shell and enter your username and password.
The first step can be used foreman start command to check whether your code can run smoothly on the Heroku, if you see the output is not an error, it explains the basic normal.
And then just use git to sync the code:
$ git init
$ git Add.
$ git commit-m "Init"
To create a Heroku application:
$ Heroku Create sample9527
If sample9527 this app name is not used in Heroku, then you will create success, the application of the link is http://sample9527.herokuapp.com/, or change the name to try, or directly with the Heroku Create let it help you with a new name.
If you need to install some plug-ins such as databases, you can see what add-on is available and then join at the command line. For example, join a Mongolab-provided MongoDB database:
$ Heroku Addons:add Mongolab
(Most add-on need you to fill in the user information in the credit card, but if you choose the free version will not be deducted fees, rest assured)
Then you can sync the program code:
After synchronization, Heroku will automatically download and install the necessary dependencies based on NPM configuration, and then start your application.
Now you can look at the application link is normal, if there are errors, you can view the log at the command line:
After modifying the code based on the error message in the log, you can submit the code again:
$ git commit-a-M "Update some code"
$ git push heroku Master
or restart the service directly with the restart command when needed:
Heroku's primary play is basically these, simple enough? Try it yourself.