英文標(biāo)題:How do I start with Node.js after I installed it?(https://nodejs.org/en/docs/guides/getting-started-guide/#how-do-i-start-with-node-js-after-i-installed-it)
當(dāng)你安裝好Node,我們試著去創(chuàng)建我們第一個(gè)web服務(wù)汽烦。先創(chuàng)建一個(gè)文件命名為"app.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}/`);
});
粘貼好后保存很钓,使用 node app.js
命令運(yùn)行你的web服務(wù)院领,瀏覽器訪問http://localhost:3000,你將會(huì)看到“Hello world”字樣模蜡。