Skip to content

当前NodeJS版本: 18.14.0

生成一个简单本地服务

js
const http = require('node: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!')
})

server.listen(port, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
})

Released under the MIT License.