CentOS 7.2 deploy Node.js development environment

   Copyright statement: This article is an original article by Shaon Puppet. Please indicate the original address for reprinting. Thank you very much. https://blog.csdn.net/wh211212/article/details/53038605

1. Introduction to Node.js##

Two, Node.js installation

[ root@linuxprobe ~]# yum --enablerepo=epel -y install nodejs npm
[ wang@linuxprobe ~]$ vi helloworld.js

var http =require('http');
http.createServer(function(req, res){
 res.writeHead(200,{'Content-Type':'text/plain'});
 res.end('Hello World\n');}).listen(1337,'127.0.0.1');
console.log('listening on http://127.0.0.1:1337/');

# run server
[ wang@linuxprobe ~]$ node helloworld.js &[1]12440[wang@linuxprobe ~]$ listening on http://127.0.0.1:1337/
# verify(it's OK if following reply is back )[wang@linuxprobe ~]$ curl http://127.0.0.1:1337/
Hello World 
[ wang@linuxprobe ~]$ npm install socket.io express
# Installing express will prompt the following warning. Longitude mother understands that this warning message can be ignored. This article only introduces the installation of Node..js environment, for Node.js itself does not introduce too much, interested students can find a way to solve this WARN.
[ wang@linuxprobe ~]$ vi chat.js

var app =require('express')();var http =require('http').Server(app);var io =require('socket.io')(http);

app.get('/',function(req, res){
 res.sendFile(__dirname +'/index.html');});

io.on('connection',function(socket){
 socket.on('chat message',function(msg){
 io.emit('chat message', msg);});});

http.listen(1337,function(){
 console.log('listening on *:1337');});[wang@linuxprobe ~]$ vi index.html

<! DOCTYPE html><html><head><title>WebSocket Chat</title></head><body><form action=""><input id="sendmsg" autocomplete="off"/><button>Send</button></form><ul id="messages" style="list-style-type: decimal; font-size: 16px; font-family: Arial;"></ul><script src="/socket.io/socket.io.js"></script><script src="http://code.jquery.com/jquery.min.js"></script><script>var socket =io();$('form').submit(function(){
 socket.emit('chat message',$('#sendmsg').val());$('#sendmsg').val('');returnfalse;});
 socket.on('chat message',function(msg){$('#messages').append($('<li style="margin-bottom: 5px;">').text(msg));});</script></body></html>[wang@linuxprobe ~]$ node chat.js
listening on *:1337

Access "http://(hostname or IP address of the server): 1337/" from the client computer to ensure that the sample application works properly

# Install development dependencies
[ root@linuxprobe ~]# yum -y install gcc make gcc-c++ openssl-devel wget
# Download the source code and unzip
[ root@linuxprobe ~]# wget https://nodejs.org/dist/v6.2.0/node-v6.2.0-linux-x64.tar.gz -P /usr/local/src
[ root@linuxprobe ~]# cd /usr/local/src && tar zxvf node-v6.2.0-linux-x64.tar.gz
# Compile and install
[ root@linuxprobe src]# cd node-v6.2.0-linux-x64
# Compiling and installing is a pit, don&#39;t fill it out first, leave it......

Recommended Posts

CentOS 7.2 deploy Node.js development environment
Centos7 configure nodejs environment
CentOS 7 configure Java language development environment
CentOS 7 configure Ruby language development environment
CentOS 7 configure php language development environment
CentOS 7 configure Python language development environment
Centos7.6 deploy django+nginx+uwsgi
CentOS 7 deploy OpenLDAP+FreeRadius
CentOS install nodejs 8
Kickstart+PXE automatically deploy CentOS6.6
Deploy GitBook under CentOS7
ubuntu16.04 deploy GPU environment
CentOS6.7 build LNMP environment
Nodejs install on centos7
Ubuntu configuration development environment
Centos7.6 build LNMP environment
lamp (centos7) installation lamp environment
CentOS6.8 install node.js npm
Install Node.js on Centos
CentOS 6.8 deploy zookeeper cluster
Ubuntu development environment configuration
CentOS 7 deploy saltstack service
Centos6.9 install npm environment
Deploy JDK+Tomcat8 under CentOS
Deploy vuepress on centos7
Centos6.8 deploy vnc service
Configure CentOS7 GPU environment
Deploy Jenkin on centos7
CentOS 7 build LNMP environment
Build a basic environment for Java development under Centos7
[CentOS environment deployment] Java7/Java8 deployment under CentOS
CentOS7 deploy vsftp (FTP) service
Build docker environment under Centos6.5
CentOS 7 install JAVA environment (JDK 1.8)
SkyWalking study notes (CentOS environment)
Centos7 set up GitBook environment
CentOS install nginx+tomcat+java+mysql operating environment
Deploy front-end projects using centOS 7
CentOS 7.2 deploy mail server (Postfix)
Centos7 decompress nodejs compressed package
Centos6 set up GitBook environment
CentOS7.7 deploy k8s (1 master + 2 node)
CentOS environment installation of Docker
ubuntu build python development environment
ubuntu builds common development environment
Centos7 deploys python3 virtual environment
Centos7.4 environment installation lamp-php7.0 tutorial
CentOS7.7 deploy k8s (3 master + 3 node + 1 client)
Deploy JobConverter + Ibreoffice environment on Ubuntu
CentOS7.7 deploy k8s + Prometheus (1 master + 2 node)
CentOS7 compile and install L(A|N)MP environment
Deploy and optimize Tomcat under Centos
Build Nginx environment on Linux (CentOS)
Configure python3 environment on centos7 and
CentOS 7.2 deploy website access log analyzer-Piwik
FFmpeg environment deployment record under centos7
CentOS6.8 Chinese/English environment switching tutorial illustration
PPTP environment deployment record under Centos
Tomcat configuration JMX in centos 6.5 environment