Linux (CENTOS7) NodeJs installation

1, download NodeJs

Download the official website: http://nodejs.cn/download/

2, upload to linux system

 I am here to upload / disk / nodejs directory below, xftp upload tool.

3, installation

In the following / disk / nodejs directory, create a soft connection, perform the following operations

ln -s /disk/nodejs/node-v10.14.1-linux-x64/bin/npm /usr/local/bin/
ln -s /disk/nodejs/node-v10.14.1-linux-x64/bin/node /usr/local/bin/

 After you create a flexible connection is completed to see if the installation was successful, do the following

the Node - v 
# execution results 
. # V10 14.1

 Here nodejs on the installation finished.

4, create a small program

I was here in the following / disk / nodejs directory, create a main.js file, create a command file and reads as follows

# Create main.js file   
# Note: After entering kicked Below, you can continue to enter the contents of the file, here directly copy the contents of the file below to main.js this file inside. Ctrl + C to save and exit.
CAT >> main.js 

# main.js file content 
var HTTP = the require ( ' HTTP ' ); 
 
http.createServer ( function (Request, Response) { 
 
    // HTTP headers are sent 
     // HTTP status values: 200 is: the OK
     // content type: text / Plain 
    response.writeHead ( 200 is , { ' the content-the type ' : ' text / Plain ' }); 
 
    // send a response "the Hello World" 
    Response.End ( 'World hello \ n- ' ); 
.}) The listen ( 8888 ); 
 
// print terminal following information 
the console.log ( ' Server running AT http://127.0.0.1:8888/ ' );

After creating main.js complete, execute the following command 

main.js the Node 
# execution results 
# Server running AT HTTP: // 127.0.0.1:8888/ 

# view the results (here I execute the following command in xshell open a separate window) 
curl HTTP: // 127.0.0.1: 8888 / 
# execution result 
# Hello World

 

Case Reference Address: http://www.runoob.com/nodejs/nodejs-http-server.html

Guess you like

Origin www.cnblogs.com/kawhileonardfans/p/10966859.html