以下是一个简单的Node.js HTTP服务器程序:

const http = require('http');

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello, world!\n');
});

server.listen(3000, () => {
  console.log('Server running at http://localhost:3000/');
});

这个程序会创建一个HTTP服务器,监听3000端口,并在收到请求时返回“Hello, world!”。您可以使用浏览器或curl等工具访问http://localhost:3000/来测试它。

nodJS写httpserver程序

原文地址: http://www.cveoy.top/t/topic/5Vi 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录