歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> 學習Linux >> Node.js~在linux上的部署,node.jslinux部署

Node.js~在linux上的部署,node.jslinux部署

日期:2017/3/3 17:31:30   编辑:學習Linux

Node.js~在linux上的部署,node.jslinux部署


熱度3 評論 129 www.BkJia.Com 網友分享於: 2017-02-17 04:02:17 浏覽數49573次

Node.js~在linux上的部署,node.jslinux部署


我們以centOS為例來說說如何部署node.js環境

一 打開centos,然後開始下載node.js包

curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
yum -y install nodejs

二 安裝gcc環境

yum install gcc-c++ make

安裝完成!

三 安裝nodejs的npm,這是一個包程序工具,類似於vs裡的nuget!

sudo yum install nodejs npm

到現在為止,我們的nodejs環境就算是安裝成功,下面我們就可以開始node.js之路了!

下面添加環境變量(快捷方式,windows裡的path指令)

//添加共享目錄
export PATH=/usr/local/python/bin:/usr/local/node/bin:$PATH

//打印node的版本
node -v

添加測試項目並監聽8080端口

#創建nodejs項目目錄
mkdir -p /usr/local/nodejs/

#創建hello.js文件
vi /usr/local/nodejs/hello.js

#內容如下:
var http = require("http");
http.createServer(function(request, response) {
    response.writeHead(200, {
        "Content-Type" : "text/plain" 
    });
    response.write("Hello World");
    response.end();
}).listen(8080); // 監聽端口號
console.log("Hello World is print!");


#後台運行
node /usr/local/nodejs/hello.js &

#浏覽器訪問
http://192.168.2.2:8100/

直接訪問浏覽器即可!

感謝各位的閱讀,希望可以幫到各位!

http://www.bkjia.com/Linuxjc/1193611.html TechArticle

Copyright © Linux教程網 All Rights Reserved