我正在尝试 MEAN 堆栈教程,并且我位于“测试初始路由 https://thinkster.io/mean-stack-tutorial/#opening-rest-routes-testing-the-initial-routes“步骤,我们使用 cURL 测试 REST 路由。
我正在尝试运行此命令来创建新帖子:
curl --data 'title=test&link=http://test.com' http://localhost:3000/posts
但是,我不断收到错误。一开始的错误是:
curl: no URL specified!
curl: try 'curl --help' or 'curl --manual' for more information
'link' is not recognized as an internal or external command,
operable program or batch file.
然后经过一番研究后,我发现我需要使用双引号,因为我在 Windows 上。但是,我仍然收到错误:
<h1>Not Found</h1>
<h2>404</h2>
<pre>Error: Not Found
at app.use.res.render.message (c:\base\demo\thinkster-mean-tutorial\flapper-news\app.js:30:13)
at Layer.handle [as handle_request] (c:\base\demo\thinkster-mean-tutorial\flapper-news\node_modules\express\lib\router\layer.js:82:5)
at trim_prefix (c:\base\demo\thinkster-mean-tutorial\flapper-news\node_modules\express\lib\router\index.js:302:13)
at c:\base\demo\thinkster-mean-tutorial\flapper-news\node_modules\express\lib\router\index.js:270:7
at Function.proto.process_params (c:\base\demo\thinkster-mean-tutorial\flapper-news\node_modules\express\lib\router\index.js:321:12)
at next (c:\base\demo\thinkster-mean-tutorial\flapper-news\node_modules\express\lib\router\index.js:261:10)
at c:\base\demo\thinkster-mean-tutorial\flapper-news\node_modules\express\lib\router\index.js:603:15
at next (c:\base\demo\thinkster-mean-tutorial\flapper-news\node_modules\express\lib\router\index.js:246:14)
at Function.proto.handle (c:\base\demo\thinkster-mean-tutorial\flapper-news\node_modules\express\lib\router\index.js:166:3)
at router (c:\base\demo\thinkster-mean-tutorial\flapper-news\node_modules\express\lib\router\index.js:35:12)</pre>
我尝试运行教程中的下一个命令:
curl http://localhost:3000/posts
这导致了完全相同的错误。然后我在浏览器中检查了网址,实际上是:http://localhost:3000/#/posts http://localhost:3000/#/posts。所以我尝试运行上面的命令,但使用 # url,它返回了该页面的 html。然后我尝试使用 # url 运行初始命令,但出现了相同的错误。
不知道接下来要尝试什么。我完全按照教程进行操作,甚至返回并复制/粘贴代码以确保我的代码完全正确,但我仍然收到错误。
你需要在express之前定义mongoose。最简单的方法是在 app.js 的最顶部定义 mongoose:
var mongoose = require('mongoose');
require('./models/Posts');
require('./models/Comments');
mongoose.connect('mongodb://localhost/news');
var express = require('express');
var path = require('path');
...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)