res.json表示不工作

时间:2016-06-10 20:36:25

标签: json node.js express

我正在尝试使用express运行一个简单的response.json(),但它不会使json本身。

node.js文件:server / app.js

"use strict";

let express = require('express');
let app = express();

app.use(express.static(__dirname + "/../client"));

app.get('/sports', function(request, response) {
  response.json( ["Cycling", "Weightlifting"] );
});

app.listen(8181, () => console.log("Listening on 8181"));

运行服务器的终端:

$ node app.js 
Listening on 8181

response.json()的“test”:

$ curl -i localhost:8181/sports
HTTP/1.1 404 Not Found
X-Powered-By: Express
X-Content-Type-Options: nosniff
Content-Type: text/html; charset=utf-8
Content-Length: 19
Date: Fri, 10 Jun 2016 20:23:17 GMT
Connection: keep-alive

Cannot GET /sports

我真的不知道发生了什么事,因为这是codechool中视频的一个例子,是这个git提交的副本,一切看起来都一样:( https://github.com/codeschool/OlympicsMEAN/commit/767c89b8b0025861cefac910f98d79ef52cb3497

由于

0 个答案:

没有答案