Nodejs Project Deployment Aliyun complete Process __js

Source: Internet
Author: User
Tags install mongodb mkdir mongodb purchase domain name aliyun
Nodejs Project Deployment Aliyun complete Process Reference Document: http://blog.csdn.net/chenlinIT/article/details/73343793Details Note: 1. Start the Nodejs service needs to open two Aliyun host Windows, one is the database Mongoose service, one is the Nodejs server 2. If the Nodejs server listens to your Aliyun host IP failure, you can try to use 0.0.0.0. (Because Aliyun limits the port number, the official says is 3398 ports but the author tries to be invalid, 0.0.0.0 's IP indicates listening to all port numbers of the current host) 1.1-Preparation work

1. What processes are needed to run a Nodejs program (1) Your computer has node (2) Your computer has NPM installed
NODE,NPM installed by default (3) your computer has a database installed
Usually the Nodejs project uses the MongoDB database (4) to write your project source code (5) to start the MongoDB service
CD to MongoDB install package path using terminal command: Mongod--dbpath=[your Data folder path] (6) Start node to run your program
CD to Node.exe directory using Terminal command: node [your Project Server portal file App.js path]
By default, installation node will automatically help you configure environment variables, and we can use node commands in any directory

2. The principle of deploying server-side projects to Aliyun is simply to install all the processes in the previous step on the Aliyun host
Can be understood as: After the purchase of the Aliyun server, Aliyun gave you a separate computer to access the Internet, and then we want to run our Nodejs program on this computer 1.2-from zero to deploy your Nodejs project 1. Into Ali Cloud to buy a server
Objective: To buy a computer in Aliyun access to the use of the computer's configuration, the more the more expensive, the purchase will tell you after the success of the computer's IP Aliyun official website: https://www.aliyun.com/Cloud Server ESC purchase Link: https:// Www.aliyun.com/product/ecs Here I strongly recommend Aliyun the latest lightweight server business, which directly supports the node platform, eliminating a lot of cumbersome configuration
Lightweight server purchase Link: Https://www.aliyun.com/product/swas

2. Purchase Domain name
Nothing to say, the better the domain name, the more expensive the price

3. Purchase database "optional"
After we buy the server, the default server has a certain amount of storage space, if the user is not very large, there is no need to buy the database database configuration is the same, if you want to learn Nodejs development, you can not buy, direct use of server host storage, can save a little money is a little money

4. Enter the console and start the deployment project

Find the lightweight server you just bought

Note: The server terminal is based on Linux, the same as the Mac system, and some of the Windows system commands have some differences

5. Binding domain Name: Click on the Nodejs server to enter the details interface binding domain name

6. Using Xshell remote connection server by default, we operate a remote server by clicking on the remote connection on the Aliyun page, and he will pop up the terminal window of your remote server on the Web page, which is not convenient for us to operate directly. Use the Xshell tool to visualize some of the files on your remote server Schell There is another advantage is that we will write the Nodejs project file uploaded to the remote server more convenient to download the address of their own Baidu, here I give a reference download address: http:// Rj.baidu.com/soft/detail/15201.html?ald

Open Xshell Panel after installation

7. Configure the node environment and NPM environment for the Aliyun server computer

Use the LS command to view the server's file list use the CD command to go to the corresponding folder use Node-v and npm-v to check your node and NPM versions
By default, Aliyun has configured node and NPM

If you want to upgrade the node and NPM versions of your Aliyun server, enter the following command (optional) wget command to download the Node.js installation package: wget https://nodejs.org/dist/v6.9.5/ Node-v6.9.5-linux-x64.tar.xz
The installation package is a compiled file, and after decompression, node and NPM already exist in the Bin folder and do not need to be compiled again. Extract file: Tar xvf node-v6.9.5-linux-x64.tar.xz

8. Install MongoDB in Terminal Input command waiting for installation: Wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.4.5.tgz
long time consuming, please be patient to unpack the installation package: Tar zxvf mongodb-linux-x86_64-3.4.5.tgz Heavy Command folder for MONGODB:MV mongodb-linux-x86_64-3.4.5 MongoDB Create the Data folder where the MongoDB is stored: mkdir/root/mymongodb, Mkdir/root/mymongodb/data
Note: The/root here refers to the name of your Aliyun server root directory, which defaults to root .

9. Start MongoDB CD to your MongoDB bin directory, for example my MongoDB installation path is: Cd/root/mongodb/bin run MongoDB service: Mongod--dbpath=[The Data folder path that you just created], For example, I'm Mongod--dbpath=/root/mymongodb/data here.

if wating for connection on Port 27017 appears successful is not feeling as basic as in your own computer deployment. Don't worry, it's just half.

10.MONGODB services need to occupy a single terminal window, so temporarily the current terminal window does not move, we have a window to start our Nodejs project

11. And so on. We currently have our terminal project on our server. I don't think so. so the critical 11th step is that we need to deploy our source code to the Aliyun server host .

12. Download Xftp xftp is the role of file transfer to the Aliyun server download the address of their own Baidu, where I give the reference address: Http://rj.baidu.com/soft/detail/18249.html?ald

13. Use Xshell to start xftp xftp download After we put aside, do not need to start alone, because as long as you install the XFTP, you can use Xshell to start
If you are individually configured xftp be sure to pay attention to the port number and our Xshell consistent, carefully go over the picture can see my Xshell port number is 22

14. Upload Nodejs project files to Aliyun server
Start xftp also need to enter your server password, do not forget the right is your local project, the left is your Aliyun host directory, drag and drop directly

15. Start your Nodejs project on the Aliyun server

Focus, Focus , focus 1.app.js file Listener's port number can not be written in your server IP address, suggested written 0.0.0.0
The reason untold, because you don't know Aliyun exactly allow you to listen to what port (do not know what port is have authority to listen to) 0.0.0.0 and 127.0.0.1 all refer to native IP, their only difference is, 0.0.0.0 is equivalent to listen to all port 2 of this server. Xshell's MongoDB window must be closed, we need to open another window to start our Nodej project.

4. Listener Port number
Server.listen (3000, ' 0.0.0.0 ', function () {
    console.log (' Server startup Success ');

16. Done, directly in any networked device input your domain name, here I will use my iphone to enter my domain name slightly
Focus, Focus , focus
1. If the domain name is not filed, will pop up the site to prohibit access, request the record of the page, not tube, more than a few times to refresh OK
4G Network is not good, WiFi refresh a few times can be 2. In your Nodejs project, you cannot have a relative path anywhere except to enlighten the module./, because the relative path in the Nodejs is equivalent to the directory where you enter the node command.

added that we can use VIM in the terminal to modify the code online, on the vim operation of its own Baidu
VIW [File path]: View File source Keyboard I: Enter edit keyboard ESC exit Edit console: Wq: Save and exit Vim

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.