nodejs+express+mysql+ Baidu BAE deploys node backstage

Source: Internet
Author: User
Tags mysql in svn

Reprint Please specify source: http://www.cnblogs.com/shamoyuu/p/node_bae.html

Baidu has an application engine, the price is very cheap, Java tomcat 4 cents a day, node 2 cents a day, I used to build a Javaweb project, today to say how to build nodejs+express+mysql backstage.

First open console.bce.baidu.com, register login complete, and then create a new application engine Bae as set up

Currently the basic version of Bae only supports node4.4.4, but it should be enough. If you are using KOA2, you can choose the Professional version, much more expensive, but support the latest node version.

SVN or git can choose according to their own needs, I am following the example of SVN.

And then you'll see our new project.

Expand "More Actions", click "Publish Settings", then turn on the "Auto release settings" switch, this means that after SVN commits, it will be automatically deployed, or you have to manually point it every time.

Copy the SVN address, and then check out locally, the account password is your Baidu account password, you can see two default files Package.json and Server.js, there are other documents to ignore.

Package.json is ..... Package.json

Server.js is the combination of the WWW file and the app.js file in Express.

And then we'll erase all two of these files.

Then we open cmd on this folder, run the Express command (Express install own Baidu), will generate an express standard project.

We need to retrofit two points:

    1. Need to add a JS extension to the Bin folder's www file and change it to Www.js
    2. You need to set the property of start in the Package.json file to "node--harmony./bin/www.js"

The reason for this change is that when the basic version of BAE is started, it must be a JS file. Plus--harmony is the syntax for BAE to support ES6.

OK, can submit, if not unexpected, you can see the initial page of Express

Note Do not submit Node_modules folder, the system will automatically help you install the

Then we write our own code in Express, add MySQL, to achieve additions and deletions to change, this step slightly. We're just going to talk about how we use MySQL in Bae.

On the left side of the BAE Deployment list page, there is a row of menus, click Expand Services

Then click "Add New Service", select MySQL, tick agree, click Buy Now. Now it's free 1G space. This database only BAE can access, other environments can not access (Baidu intranet)

We can see our new MySQL database in the Extension service interface, click on the database name (the name is garbled, automatically generated) can see all the information of the database

↑↑↑ This is the database configuration in the BAE environment ↑↑↑

I didn't want to get the local and BAE two sets of configurations to switch the trouble and make the local into the same as BAE. Here's how.

Create a MySQL database with Navicat, the database name is the same garbled name you see here.

The port of the database is 4050

The address of the database is sqld.duapp.com, this directly modifies the system hosts file, adding a line 127.0.0.1 sqld.duapp.com,

The database's account number and password, respectively, are your AK and SK, you can click on the question mark, and then click View to get to

Then create a new user and password locally on MySQL.

It should be noted that navicat new user, because the user name is too long, you can change another MySQL tool, I use the Mysql-front to create a new user.

After the above operation, your local database configuration is the same as Bae, the time of submission will not be modified.

The end, the scattered flowers

nodejs+express+mysql+ Baidu BAE deploys node backstage

Related Article

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.