CentOS安裝NodeJS及Express開發架構

來源:互聯網
上載者:User

標籤:centos   server   nodejs   

本文示範在Linux上安裝NodeJS及Express開發架構註:本人在http://www.nodejs.org/官網上下載了nodejs最新版本NodeJS v0.10.29 但是在./configure的時候,說沒有找到路徑,無奈之下,只好將nodejs版本降低到v0.10.24。現在講運行步驟記下,以免將來忘掉,

安裝過程如下:Step 1、確認伺服器有nodejs編譯及依賴相關軟體,如果沒有可通過運行以下命令安裝。

[[email protected] local]# yum -y install gcc gcc-c++ openssl-devel
Step 2、下載NodeJS源碼包並解壓。

[[email protected] local]# wget http://nodejs.org/dist/v0.10.24/node-v0.10.24.tar.gz[[email protected] local]# tar zxvf node-v0.10.24.tar.gz[[email protected] local]# cd node-v0.10.24
Step 3、配置、編譯、安裝。

[[email protected] node-v0.10.24]# ./configure --prefix=/usr/local/node[[email protected] node-v0.10.24]# make && make install
Step 4、接下來配置Node環境

[[email protected] node-v0.10.24]# vim /etc/profile
#set nodejs envexport NODE_HOME=/usr/local/nodeexport PATH=$NODE_HOME/bin:$PATHexport NODE_PATH=$NODE_HOME/lib/node_modules:$PATH[[email protected] node-v0.10.24]# source /etc/profile    
   --重啟生效Step 5、測試是否安裝成功

[[email protected] node-v0.10.24]# node -vv0.10.24
出現NodeJS版本號碼則表示OK。Step 6、NodeJS之Hello World

[[email protected] node-v0.10.24]# node> console.log(”Hello NodeJS, I'm Bob.Z“);Hello NodeJS, I'm Bob.Zundefined> 
輸出:Hello NodeJS, I‘m Bob.ZStep 7、安裝Express開發架構

[[email protected] local]# npm install express -g
Step 8、建立Demo項目

[[email protected] local]# express DemoApp[[email protected] local]# cd DemoApp[[email protected] DemoApp]# 
Step 9、進入項目目錄並安裝項目相依元件

[[email protected] local]# cd DemoApp[[email protected] DemoApp]# npm install
Step 10、相依元件安裝完成後啟動app

[[email protected] DemoApp]# node appExpress server listening on port 3000

最後通過瀏覽器訪問伺服器3000連接埠,頁面顯示,Express

Welcome to Express


Node + Express成功運行,順利開啟Node開發之旅,enjoy it!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.