您的位置:首页 > 运维架构 > Linux

CentOS 环境搭建并测试Node.js服务器开发环境

2017-09-09 10:51 806 查看

安装

使用root用户:

[xiaoqw@VM_42_160_centos ~]$ yum install nodejs
[xiaoqw@VM_42_160_centos ~]$ yum install npm


CentOS 6.5 腾讯云主机安装后不用配置环境变量,直接可用。

[xiaoqw@VM_42_160_centos ~]$ node --version
v0.10.48


基础测试

[xiaoqw@VM_42_160_centos nodejs]$ pwd
/home/xiaoqw/nodejs
[xiaoqw@VM_42_160_centos nodejs]$ cat node.js
console.log("Hello World"); # VIM打开node.js文件,编写本行内容
[xiaoqw@VM_42_160_centos nodejs]$ node node.js
Hello World #成功输出,说明最基本的开发环境是可以了。


创建一个Server应用

代码来自http://www.runoob.com/nodejs/nodejs-http-server.html

var http = require('http');

http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain});
response.end('Hello World\n');
}).listen(8080);

console.log('Server running at ' target='_blank'>http://yixzm.cn:8080/');[/code] 
执行结果:

[xiaoqw@VM_42_160_centos nodejs]$ node server.js
Server running at http://yixzm.cn:8080/[/code] 
                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息