CentOS 7 配置JS语言开发环境(JavaScript)
来源:互联网 发布:c语言求数组最小值 编辑:程序博客网 时间:2024/06/06 18:43
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.jsvar 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.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');});[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.jslistening 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 -vv4.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/bashsource /opt/rh/rh-nodejs4/enableexport X_SCLS="`scl enable rh-nodejs4 'echo $X_SCLS'`"
0 0
- CentOS 7 配置JS语言开发环境(JavaScript)
- CentOS 7 配置Ruby语言开发环境
- CentOS 7 配置Java语言开发环境
- CentOS 7 配置Python语言开发环境
- CentOS 7 配置php语言开发环境
- CentOS 7 配置Ruby语言开发环境
- CentOS 配置 Go 语言开发环境
- CentOS 6.8 配置GO语言开发环境
- CentOS 6.8 配置GO语言开发环境
- Centos开发环境配置
- centos 开发环境配置
- Centos 7 配置Java开发环境
- 使用centOS 7配置nodeJS开发环境
- js 开发环境配置
- Eclipse开发Javascript环境配置(含EXTJs配置)javascript
- CentOS 7 环境配置
- Centos下配置node.js环境
- Eclipse开发Javascript环境配置
- 理解MIPS指令集中的ll (load linked) 和 sc (store conditional)指令
- 微信开通筛选器
- 前台传过来字符串 把它拼成数组
- 异常
- GreenDao教程(3):一对一,一对多,多对多
- CentOS 7 配置JS语言开发环境(JavaScript)
- 4.20 学习总结
- 微信app开发支付接口相关
- TCP连接异常终止分析
- Linux下的proc目录详解
- python unittest之断言及示例
- 面向对象
- 蓝桥杯JAVA语言B组_立方变自身
- Java的输入与输出