Teach you how to deploy the Node. js application on heroku cloud platform, herokunode. js

Source: Internet
Author: User
Tags node server git commands mongolab heroku logs heroku toolbelt

Teach you how to deploy the Node. js application on heroku cloud platform, herokunode. js

Although AWS has also launched its own PaaS platform called Elastic Beanstalk, heroku has many third-party add-on, such as MongoDB, mysql, redis, and memcached, there are also various plug-ins such as message queue, sms and email, backend batch processing, search, and automatic monitoring. They are much better than AWS in the ecological environment.

That is to say, there is a ready-made Node on heroku. in the js PaaS running environment, there are many add-on operations. Data is automatically backed up to AWS S3 every day. You only need to use git commands to push the code up, you don't need to worry about anything else. Is there anything better in the world than programmers?

Therefore, for the benefit of netizens, I will summarize the deployment steps today.

Suppose you already have a node named sample. js application. The code is stored in/Home/Apps/sample9527. The directory contains your server-side core js file server. js, now you have cd under this directory.

To enable heroku to identify your application, you need to add a file Procfile under this directory with a line of code:

web: node server.js

(Here, the web: node tells heroku that you want to deploy a node. js web application. The server. js below is the file name of the core program code on your server)

Okay. Now the deployment is ready.

First, you need to register a user on www.heroku.com. the user name is your email address. Then install Heroku Toolbelt, a command line tool that allows you to directly use commands in shell to publish code, view system status, modify server configurations, and so on.

Then use the heroku login command in shell to log on and enter your username and password.

$ heroku login

In the first step, run the foreman start command to check whether your code can run smoothly on heroku. If no error is reported in the output, it indicates that it is basically normal.

$ foreman start

Then, use git to synchronize the Code:

$ git init$ git add .$ git commit -m "init"

Create a heroku application:

$ heroku create sample9527

If no one uses the app name sample9527 on heroku, you will create the app successfully. The link to the app is http://sample9527.herokuapp.com/. if you do not change the name, try again. Use heroku create to get a new name.

If you need to install some plug-ins such as databases, you can see what add-on is available for it, and then add it in the command line. For example, add a MongoDB database provided by MongoLab:

$ heroku addons:add mongolab

(For most add-on instances, you need to enter your credit card in your user information. However, if you use a free version, you will not be charged. Do not worry)

Then you can synchronize the program code:

$ git push heroku master

After synchronization, heroku automatically downloads and installs necessary dependencies according to the npm configuration, and then starts your application.

Now, you can go to the application link to check whether it is normal. If there is an error, you can view the log in the command line:

$ heroku logs

After modifying the code based on the error information in the log, you can submit the code again:

$ git commit -a -m "update some code"$ git push heroku master

Or use the restart command to restart the service as needed:

$ heroku restart

This is basically the basic gameplay of heroku. Is it easy enough? Try it yourself.


How to deploy nodejs on heroku

Heroku is a cloud Application Deployment platform. You can deploy simple applications (including java, ruby, and node. js applications) on it ).
Here is just a test, so with the Express framework, you can deploy your own applications according to heroku's reference.
Register
First, you must register a heroku account. This is very simple, just a mailbox.
Download heroku's own command line tool Toolbelt
Here I am on the mac platform. With homebrew, you can directly install it with one click (brew install heroku). You can download the corresponding installation package from the official website on your own platform.
Log on to your computer
Open the command line, enter heroku login, and enter the account and password as prompted.
Start Application Deployment
This section describes how to deploy node. js applications. You can perform other operations on other applications by following the steps on the official website.
Deploy the node. js Application
Write Applications
Here I directly use express to generate an application
Modify the package. json File
Example:

{

"Name": "MyMobile ",

"Version": "0.0.1 ",

"Private": true,

"Scripts ":{

"Start": "node app. js ",

"Postinstall": "./node_modules/bower/bin/bower install"

},

"Dependencies ":{

"Express ":"~ 3.4.5 ",

"Jade ":"*",

"Bower ":"*"

},

"Engines ":{

"Node": "0.10.x ",

"Npm": "1.3.x"

}

}

Add a Procfile File
Note that the Procfile file should be placed in the root directory named Procfile. Simply add one web: node web. js.
Use git to create a repository
Deploy to heroku
Heroku create
Git push heroku master
Run the application
Command Line input heroku ps: scale web = 1
You can check whether the deployment is successful. Enter heroku ps in the command line. If the output is normal, the deployment is successful.
View
Enter heroku open in the command line to open the browser, which automatically displays the application you are running in the browser.
Add your own domain name
In the DNS resolution area, use CNAME to map your own domain name to the domain name assigned to you by heroku.
Here I also use bower, so a bower command is used in package. json. In this way, heroku will automatically download the corresponding library according to the dependencies in your bower. json before running. In this way, you do not need to add these libraries to the repository to reduce the project volume.
Link to the original article:... the remaining full text>

What is the cloud deployment architecture of the cloud platform?

The cloud computing architecture can be divided into four layers, three of which are horizontal, namely the display layer, middleware layer, and infrastructure layer, the layer-3 technology provides rich cloud computing capabilities and a friendly user interface. The layer is vertical, called the management layer, to better manage and maintain the layer-3 layer. The following describes the functions of each layer and the main technologies that belong to this layer.

Display Layer

This layer is mainly used to display the content required by users in a friendly way, and will take advantage of the various services provided by the middleware layer below. There are five main technologies:
HTML: The standard Web page technology is mainly HTML 4, but the HTML5 to be launched will promote the development of Web pages in many aspects, such as video and local storage.
JavaScript: a dynamic language for Web pages. using JavaScript, You can greatly enrich web page functions. The most popular JS frameworks include jQuery and Prototype.
CSS: it is mainly used to control the appearance of a web page, and allows the content of the page to be elegantly separated from its representation.
Flash: The most common RIA (Rich Internet Applications) technology in the industry. It can provide Web-based Rich Applications that cannot be provided by HTML and other technologies at this stage, and it is very good in terms of user experience.

Silverlight: The RIA technology from Microsoft, the industry's leader, is slightly inferior to Flash, but it is very friendly to developers because it can use C # for programming.
On the display layer, most cloud computing products tend to be HTML, JavaScript, and CSS. However, RIA technologies such as Flash and Silverlight are also useful, for example, VMware vCloud uses Flash-based Flex technology, and Microsoft's cloud computing products will certainly use Silverlight in the future.
Middleware layer
This layer is a link between the two. It provides a variety of services, such as cache services and REST services, based on the resources provided by the following infrastructure layer, and these services can be used to support the display layer, it can also be called directly by users. There are five main technologies:
REST: With REST technology, some services supported by the middleware layer can be conveniently and elegantly provided to callers.
Multi-tenant: enables a single application instance to serve multiple organizations, and maintains good isolation and security. This technology can effectively reduce the application purchase and maintenance costs.
Parallel Processing: to process massive amounts of data, we need to use a large X86 cluster for large-scale parallel processing. Google's MapReduce is a representative of this.
Application Server: based on the original application server, cloud computing is optimized to a certain extent, for example, Jetty Application Server for Google App Engine.
Distributed cache: distributed cache technology not only effectively reduces the pressure on backend servers, but also speeds up response. The most famous example of distributed cache is Memcached.
For many PaaS platforms, such as the Heroku cloud platform used to deploy Ruby applications, application servers and distributed cache are essential, and REST technology is also commonly used for external interfaces, multi-tenant technology is mainly used in the background of SaaS applications, such as Force.com multi-tenant kernel for supporting Salesforce's Sales Cloud and other applications. Parallel Processing technology is often released as a separate service, for example, Amazon Elastic MapReduce.

Infrastructure Layer

This layer is used to prepare computing, storage, and other resources for the middleware layer or users. There are four main technologies:
Virtualization: it can also be understood as the "Multi-tenant" of the infrastructure layer, because through virtualization technology, multiple virtual machines can be generated on a physical server, in addition, these virtual machines can be fully isolated, which not only reduces the server purchase cost, but also reduces the server O & M cost, mature X86 virtual machines ...... remaining full text>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.