English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Deployment Tutorial of Node.js Environment on Linux

Let's take CentOS as an example to explain how to deploy the node.js environment

One: Open CentOS and start downloading the node.js package

 curl --silent --location https://rpm.nodesource.com/setup_6.x | bash - 
yum -y install nodejs 

 

Two: Install gcc environment

yum install gcc-c++ make 

Installation completed!

Three: Install npm for nodejs, which is a package program tool, similar to nuget in VS!

sudo yum install nodejs npm 

So far, our nodejs environment is successfully installed, and we can start the journey of node.js now!

Below add environment variables (shortcut, path command in windows)

//Add shared directory
export PATH=/usr/local/python/bin:/usr/local/node/bin:$PATH
//Print node version
node -v 

Add test project and listen8080 port

#Create nodejs project directory
mkdir -p /usr/local/nodejs/
#Create hello.js file
vi /usr/local/nodejs/hello.js

The content is as follows:

var http = require("http");
http.createServer(function(request, response) {
  response.writeHead(200, {
    "Content-Type" : "text/plain" 
  });
  response.write("Hello World");
  response.end();
}).listen(8080); // Listen on port number
console.log("Hello World is print!");
#Run in the background
node /usr/local/nodejs/hello.js &
#Browser Access
http://192.168.2.2:8100/

Access the browser directly!

That's all for this article. I hope it will be helpful to everyone's learning and I also hope everyone will support the Yelling Tutorial.

Statement: The content of this article is from the Internet, the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, does not edit manually, and does not bear relevant legal responsibility. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (Please replace # with @ when sending an email to report abuse, and provide relevant evidence. Once verified, this site will immediately delete the infringing content.)

You May Also Like