分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

nodejs v8.9.4 安装

发布时间:2023-09-06 01:36责任编辑:沈小雨关键词:jsnodejs
一.安装
环境Centos7.3 64位

wget https://nodejs.org/dist/v8.9.4/node-v8.9.4.tar.gz

cd node-v8.9.4/

./configure --prefix=/usr/local/nodejs
make
make install

二.nodejs设置环境变量
vim /etc/profile.d/nodejs.sh
#输入以下内容
export NODEJS_HOME=/usr/local/nodejs
PATH=$PATH:$NODEJS_HOME/bin

刷新环境变量
source /etc/profile.d/nodejs.sh

三.测试
运行项目web.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(‘Server running at http://127.0.0.1:1337/‘);
To run the server, put the code into a file example.js and execute it with the node program from the command line:

% node example.js
Server running at http://127.0.0.1:1337/
Here is an example of a simple TCP server which listens on port 1337 and echoes whatever you send it:

var net = require(‘net‘);

var server = net.createServer(function (socket) {
socket.write(‘Echo server\r\n‘);
socket.pipe(socket);
});

server.listen(1337, ‘127.0.0.1‘);

nodejs v8.9.4 安装

原文地址:http://blog.51cto.com/shenshen/2061107

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved