localhost:3000不呈现节点教程

时间:2017-01-06 21:16:29

标签: node.js mongoose mean-stack

我目前正在阅读thinkster MEAN教程 - 并且真正开始学习堆栈。我白天忙着建设,一切都很好。我回到家的那一刻,我什么都跑不了。使用npm start时,我可以使用curl GET命令通过API层获取文档,构建本身不会呈现,我得到404.见下文:

> Not Found 404 Error: Not Found at
> C:\Users\user\Documents\Stuff\misc\AngularTutorial\MEAN-Chapterized\flapper-news\app.js:37:13
> at Layer.handle [as handle_request]
> (C:\Users\user\Documents\Stuff\misc\AngularTutorial\MEAN-Chapterized\flapper-news\node_modules\express\lib\router\layer.js:95:5)
> at trim_prefix
> (C:\Users\user\Documents\Stuff\misc\AngularTutorial\MEAN-Chapterized\flapper-news\node_modules\express\lib\router\index.js:312:13)
> at
> C:\Users\user\Documents\Stuff\misc\AngularTutorial\MEAN-Chapterized\flapper-news\node_modules\express\lib\router\index.js:280:7
> at Function.process_params
> (C:\Users\user\Documents\Stuff\misc\AngularTutorial\MEAN-Chapterized\flapper-news\node_modules\express\lib\router\index.js:330:12)
> at next
> (C:\Users\user\Documents\Stuff\misc\AngularTutorial\MEAN-Chapterized\flapper-news\node_modules\express\lib\router\index.js:271:10)
> at
> C:\Users\user\Documents\Stuff\misc\AngularTutorial\MEAN-Chapterized\flapper-news\node_modules\express\lib\router\index.js:618:15
> at next
> (C:\Users\user\Documents\Stuff\misc\AngularTutorial\MEAN-Chapterized\flapper-news\node_modules\express\lib\router\index.js:256:14)
> at Function.handle
> (C:\Users\user\Documents\Stuff\misc\AngularTutorial\MEAN-Chapterized\flapper-news\node_modules\express\lib\router\index.js:176:3)
> at router
> (C:\Users\user\Documents\Stuff\misc\AngularTutorial\MEAN-Chapterized\flapper-news\node_modules\express\lib\router\index.js:46:12)
> at Layer.handle [as handle_request]
> (C:\Users\user\Documents\Stuff\misc\AngularTutorial\MEAN-Chapterized\flapper-news\node_modules\express\lib\router\layer.js:95:5)
> at trim_prefix
> (C:\Users\user\Documents\Stuff\misc\AngularTutorial\MEAN-Chapterized\flapper-news\node_modules\express\lib\router\index.js:312:13)
> at
> C:\Users\user\Documents\Stuff\misc\AngularTutorial\MEAN-Chapterized\flapper-news\node_modules\express\lib\router\index.js:280:7
> at Function.process_params
> (C:\Users\user\Documents\Stuff\misc\AngularTutorial\MEAN-Chapterized\flapper-news\node_modules\express\lib\router\index.js:330:12)
> at next
> (C:\Users\user\Documents\Stuff\misc\AngularTutorial\MEAN-Chapterized\flapper-news\node_modules\express\lib\router\index.js:271:10)
> at SendStream.error
> (C:\Users\user\Documents\Stuff\misc\AngularTutorial\MEAN-Chapterized\flapper-news\node_modules\serve-static\index.js:121:7)

最新版本的git repo位于:codepen

如果你能指出我正确的方向,那将是值得赞赏的。

1 个答案:

答案 0 :(得分:0)

  

GET / home

为何选择404?

您的index.js路径文件夹中GET上的/home没有任何配置。因此,你得到404。同样,您在GET上也没有为/配置路由。

  

GET /

您也可以获得404。因此,您需要为这些端点配置路由

router.get('/home', function (req, res) {
    res.send({
        msg: 'hello world from /home'
    });
});

router.get('/', function (req, res) {
    res.send({
        msg: 'hello world from at /'
    });
});