How to deploy nodejs on linux and run hello world and nodejshello

Source: Internet
Author: User

How to deploy nodejs on linux and run hello world and nodejshello

I have been engaged in front-end services for more than a year and have never been familiar with the deployment of linux services. I knew that some time ago I had an idea. How can I put my code on a linux server like my O & M team. so I started my pitfall journey, which is recorded here by the way.

Ps: the files to be downloaded in this article include:

  1. VMware download
  2. Linux
  3. Nodejs
  4. Xshell

The file is large. before getting on the bus, you can prepare to download the file. Anyway, I used several games of LOL to download the file.

First install VMware

1. Download VMware

Because we do not have to program on linux (unless you are a good guy | installation force talents), we chose to install linux on a virtual machine, currently, the mainstream Virtual Machine platforms include VMware and virtualbox. The former is paid, and the latter is the free version. you can install it at will. We use VMware here.

2. Install VMware

Double-click the downloaded installation package to start installation...

A. For those with obsessive-compulsive disorder on my interface, there is no problem with old tie ^-^


B. If you don't agree here, then you don't have it. Then v_v


C. When the emphasis is reached here, for some clean programmers who do not want to install the application software on their own c drive, you need to click the change button on this interface.


D. I don't know if you have any magical operations. As a lazy person, I just replaced C with D directly.


E. Then let's go to the crazy next step --> click Install at the end and the computer will start to work.

F. After the installation is complete, the following page is displayed. Click the license button here (we strongly recommend that you buy a genuine version)


G. after entering the license page, I thought of DU Niang without knowing it. Here, I strongly recommend that you use genuine software.


H. Click Finish on the final completion page. Now the VMware installation is complete.

Install linux

1. Download linux

We will not go into details about the myth of the birth of linux.

: Http://www.bkjia.com/softs/188482.html

2. install linux

A. Double-click the VMware button on the desktop and click the huge "create VM" button.


B. Select a typical installation package and click Next. if the system does not match the linux installation package you downloaded on this page, you need to manually select

 


C. here you need to name your Virtual Machine



D. Old Rules C-> D


E. These things are not very good, and the next step is to complete the virtual machine configuration.


F. The advantage of VMware is that we don't have to do anything so far. You can try it out and beat LOL. VMware has helped us with the rest of the work.


G. After the installation is complete, we enter the linux interface, which is not as bad as we think ^-^


H. Use xshell to link linux


A) There is no difficulty in installing xshell. Let's not talk about it here. First, we get the ip address of the virtual machine.

Click the linux button. In the Password box, enter the password set for installing the VM. After completing the basic settings, enter

Liunx desktop-> right-click-> open in terminal to open the liunx console, enter the ifconfig command, and press Enter.


B) Open xshell and use the alt + n shortcut


Enter the ip address obtained in the previous step for the host name.




C) input the ifconfig output content in xshell and output it continuously in the VM. The xshell link is successfully linked.


1. Enter the installation directory

 cd /usr/local/

2. Upload the nodejs installation package

Rz-> select the downloaded node installation package file


3. decompress the nodejs installation package

 xz -d node-v8.1.2-linux-x64.tar.xz tar -xvf node-v8.1.2-linux-x64.tar

4. Rename

 mv node-v8.1.2-linux-x64 node

5. Add Environment Variables

Vim/etc/profile-> and add three lines at the end of the file (Baidu For vim operations) export NODE_HOME =/usr/local/node export PATH = $ PATH: $ NODE_HOME/bin export NODE_PATH = $ NODE_HOME/lib/node_modules after configuration is complete, run source/etc/profile and enter node-v in the command line. run vim/root /. bashrc and add the source etc/profile to the end of this file .....

6. Create a hello world Program

mkdir -p /usr/local/demo/vim /usr/local/demo/helloworld.js

Enter the following content in the helloworld. js file:

Var http = require ('http'); http. createServer (function (req, res) {res. end ('Hello world... ')}). listen (8080); console. log ('service started, listening port 8080 ...... ')

Now we can access the service through the Virtual Machine.


Access node services through virtual machines

But it cannot be accessed on the physical host.

Why ??? Disable Firewall

Baidu discovered that the firewall was originally enabled for the Virtual Machine for half a day, so the physical host could not be accessed. Execute the following two commands.

Systemctl stop firewalld. service # stop firewallsystemctl disable firewalld. service # disable firewall startup

Open a browser to access http: // 192.168.79.128: 8080/


This article records my initial node. js step-by-step journey, hoping to help new students and give me some advice.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

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.