1.下載安裝node,傻瓜式安裝 下載地址:https://nodejs.org/en/download/
2.終端中輸入 node -v ,返回版本號,
終端中輸入 npm -v ,返回版本號,安裝成功。
3.配置:
在Finder中打開用戶目錄(就是Mac管理員,點開側欄打開目錄,創建一個Js文件,在js文件中輸入下列內容)
const http = require('http');
const hostname = '127.0.0.1';
const port = 1337;
http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World\n');
}).listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
保存成功之后,打開終端
輸入 node helloworld.js得到
復制ip地址到瀏覽器打開
配置成功!