從官網得到,測試可以使用,本機為linux mint18
官網原文
鏈接在此
// 直接使用sudo apt install nodejs安裝的版本較老,而且命令必須使用nodejs
// 使用下面的方法,終端輸入node即可使用,而且是最新版本
// 安裝4.x版本穩定版,現在為v4.4.7LTS curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash - sudo apt-get install -y nodejs
// 安裝6.x開發版,現在為v6.0.3current curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - sudo apt-get install -y nodejs
// Optional: install build tools // To compile and install native addons from npm you may also need to install build tools: sudo apt-get install -y build-essential
// 測試是否安裝成功: // 新建文件server.js var http = require('http'); http.createServer(function (request, response) { // 發送 HTTP 頭部 // HTTP 狀態值: 200 : OK // 內容類型: text/plain response.writeHead(200, {'Content-Type': 'text/plain'}); // 發送響應數據 "Hello World" response.end('Hello World\n'); }).listen(8888); // 終端打印如下信息 console.log('Server running at http://127.0.0.1:8888/');
使用node --version,查看版本號
v4.4.7
在server.js文件目錄下輸入node server.js 開啟服務
輸入node server.js
顯示Server running at http://127.0.0.1:8888/
保持終端不關閉
在瀏覽器端 訪問http://127.0.0.1:8888/ 或 localhost:8888 即可
顯示hello world