1. 新建測試程序(官網提供):
`consthttp=require('http')
consthostname='127.0.0.1'
constport=3000
constserver=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. 打開nodejs cmd 打開nodejs環境
3. 在瀏覽器里輸入127.0.0.1:3000
?打開專屬你的第一個nodejs程序~hello world~