CentOS 7 配置JS语言开发环境(JavaScript)
CentOS 7 配置JS语言开发环境(JavaScript)
安装ServerSide JavaScript环境“Node.js”
- 安装Node.js和包管理工具npm
[root@linuxprobe ~]# yum -y install epel-release
[root@linuxprobe ~]# yum --enablerepo=epel -y install nodejs npm
- 创建一个测试工具
[root@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
[root@linuxprobe ~]$ node helloworld.js &
# verify (it's OK if following reply is back )
[root@linuxprobe ~]$ curl http://127.0.0.1:1337/
Hello World
- 安装Socket.IO并使用WebSocket创建测试
[root@linuxprobe ~]$ npm install socket.io express
[root@linuxprobe ~]$ vi chat.jsvar 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');
});[root@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('');return false;});socket.on('chat message', function(msg){$('#messages').append($('<li style="margin-bottom: 5px;">').text(msg));});
</script>
</body>
</html>[root@linuxprobe ~]$ node chat.js
listening on *:1337
- 客户端浏览器访问测试http://10.1.1.53:1337/
安装ServerSide JavaScript环境Node.js 4(LTS)
- 可以从CentOS SCLo软件存贮库进行安装
# install from SCLo
[root@linuxprobe ~]# yum --enablerepo=centos-sclo-rh -y install rh-nodejs4
- 设置环境变量
# load environment variables
[root@linuxprobe ~]# scl enable rh-nodejs4 bash
[root@linuxprobe ~]# node -v
v4.4.2
[root@linuxprobe ~]# which node
/opt/rh/rh-nodejs4/root/usr/bin/node
- 设置登录时自动启用Node.js 4
[root@linuxprobe ~]# vi /etc/profile.d/rh-nodejs4.sh
#!/bin/bash
source /opt/rh/rh-nodejs4/enable
export X_SCLS="`scl enable rh-nodejs4 'echo $X_SCLS'`"
CentOS 7 配置JS语言开发环境(JavaScript)相关推荐
- yum安装ruby_CentOS 7下配置Ruby语言开发环境的方法教程
本文跟大家分享的是在CentOS 7下配置Ruby语言开发环境的方法教程,分享出来供大家参考学习,下面来看看详细的介绍: 安装Ruby 2.2 CentOS7存储库中的Ruby版本为2.0,但如果需要 ...
- VS Code配置Go语言开发环境
VS Code配置Go语言开发环境 Go语言是采用UTF8编码的,理论上使用任何文本编辑器都能做Go语言开发.大家可以根据自己的喜好自行选择.编辑器/IDE没有最好只有最适合 1.安装中文简体插件 点 ...
- Linux搭建部落冲突,GitHub - lioyou/nvim-coc: 在Win10上使用WSL安装Ubuntu,并安装neovim+coc.nvim,配置多种语言开发环境......
在windows上使用Ubuntu并配置多种语言开发境 0 效果 使用C++ 1 开启WSL服务并安装Ubuntu 自己利用搜索引擎去查找相关资料并安装,很容易的就两步 2 安装各类编程语言的相关依赖 ...
- Ubuntu 配置 Go 语言开发环境(Sublime Text+GoSublime)
本文针对的 Go 语言版本为 1.3,之前也有相关文章讲解如何在 Ubuntu 下配置Go语言的开发环境,但时过境迁,一些方法已经不相同或者不必要.虽讲的是 Ubuntu 下安装配置过程,但 Wind ...
- vs 如何配置组件 c语言,VS Code配置C语言开发环境的超详细教程
今年有个C语言的课程,以往上C语言课都是用VC++6 作为开发环境,VC6实在是太古老了,这个学期想用Visual Studio Code来配置C语言的开发环境.把整个环境变量配置.工具安装使用的步骤 ...
- notepad 配置c语言开发环境,用notepad++打造c/c++开发环境
用notepad++打造c/c++开发环境 (2014-01-07 11:21:18) 标签: c/c notepad 开发 it 本文介绍如何使用开源软件notepad++,来打造c/c++开发环境 ...
- Golang VS Code 配置 Go 语言开发环境
前言 前面我已经讲过 GoLand 的安装,当然,你也可以使用 VS Code 来进行开发. VS Code 是微软开源的一款编辑器, 本文主要介绍如何使用VS Code搭建Go语言的开发环境. 下载 ...
- 在CentOS中安装gcc配置c语言开发环境(转)
From:http://hsl46346.blog.163.com/blog/static/17764050201062074955358/ From: CentOS 5.4 下gcc和gcc-c++ ...
- linux 安装go编译器,CentOS 7 安装 go 语言开发环境
安装 VSCode 编辑器 安装 golang 安装 使用系统包管理工具安装:sudo yum install golang 查看安装到哪个目录:rpm -ql golang |more 测试安装是否 ...
最新文章
- 2022华为首个「天才少年」,是从绩点1.8逆袭的复旦博士
- Linux分区、LVM等简述
- kali 安装volatility_volatility取证学习-linux
- mysql 创建、修改、删除表
- MATLAB随机模拟
- python 归一化_数据的标准化和归一化
- lombok原理_十分钟搞懂Lombok使用与原理
- 加泰罗尼亚理工大学 计算机 排名,西班牙加泰罗尼亚理工大学排名
- 输入一个链表,按链表值从尾到头的顺序返回一个ArrayList。
- 软件工程——总体设计与详细设计
- J2ME、J2SE、J2EE 小讲
- Typo3 CVE201912747 反序列化漏洞分析
- python使用seek函数报错:io.UnsupportedOperation: can't do nonzero end-relative seeks
- 网页怎么算切屏_电脑怎么切屏
- 2021-11-23----韩顺平Java入门第十四天
- 曲线解决问题。HTTP ERROR 403 No valid crumb was included in the request【重装到带CSRF 的版本】
- “软件工程”学习笔记、复习资料
- c语言打字游戏,用C语言实现的打字游戏
- 解决GitLab 上传头像不显示的问题
- 英语中的现在分词和过去分词