环境:MAC OS X10.12
1. 先安装 Homebrew
请参考《安装Homebrew》。
2. 安装 node
$ brew install node
$ node -v
3. 测试 node
(1) vim test.js
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
(2) node test.js
(3) curl http://localhost:3000
1. 先安装 Homebrew
请参考《安装Homebrew》。
2. 安装 node
$ brew install node
$ node -v
3. 测试 node
(1) vim test.js
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
(2) node test.js
(3) curl http://localhost:3000
没有评论:
发表评论