node怎么编写数据接口?

初学node,如何编写数据接口,用以ajax交互呢?求demo或教程

阅读 2.4k
1 个回答

可以看看Express或者koa
直接写nodejs的话的node

下面的代码,ajax中的dataType修改成text,就能请求到

const http = require('http');

const hostname = '127.0.0.1';
const port = 1337;

http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });  
  res.end('Hello World\n');
}).listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题