Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 得到http://localhost:4000/rugs 500(内部服务器错误)_Node.js_Angularjs_Routing_Mean Stack_Crud - Fatal编程技术网

Node.js 得到http://localhost:4000/rugs 500(内部服务器错误)

Node.js 得到http://localhost:4000/rugs 500(内部服务器错误),node.js,angularjs,routing,mean-stack,crud,Node.js,Angularjs,Routing,Mean Stack,Crud,我正在尝试制作一个卑鄙的CRUD应用程序。我不确定我的哪些路由已关闭,但我似乎无法与mongodb通信以显示数据。当“rug list.component.ts”调用“rug.service.ts”中的getRugs()服务时,调试器似乎中断了。(我还想知道:后端文件中的路径名是否需要与前端文件中的路径名匹配?) 如有任何建议,将不胜感激。:) »地毯服务.ts(前端) »server.js(后端) »rug.route.js(后端) »应用程序路由.module.ts(不确定是否有必要)(前端

我正在尝试制作一个卑鄙的CRUD应用程序。我不确定我的哪些路由已关闭,但我似乎无法与
mongodb
通信以显示数据。当“rug list.component.ts”调用“rug.service.ts”中的
getRugs()
服务时,调试器似乎中断了。(我还想知道:后端文件中的路径名是否需要与前端文件中的路径名匹配?)

如有任何建议,将不胜感激。:)

»地毯服务.ts(前端)

»server.js(后端)

»rug.route.js(后端)

»应用程序路由.module.ts(不确定是否有必要)(前端)


确保前端文件rug.service.ts中的“this.http.get/put/post”与后端文件rug.route.js中的“rugrouts.route(pathname).get/put/post(…)”匹配。

确保前端文件rug.service.ts中的“this.http.get/put/post”与“rugrouts.route(pathname).get/put/post(…)”匹配在后端文件rug.route.js中。

当您发出get请求时,您在后端终端中看到了什么错误。什么是
查找
?对我来说,它看起来像一个mongoose/mongodb函数。在这种情况下,您应该仔细阅读文档,了解如何使用它。当您发出get请求时,您在后端终端中看到了什么错误。什么是
查找
?对我来说,它看起来像一个mongoose/mongodb函数。在这种情况下,你应该仔细阅读文档,了解如何使用它
...

@Injectable({ providedIn: "root" })
export class RugService {
    private uri = 'http://localhost:4000/rugs';

    constructor(private http: HttpClient) { }

    getRugs() {
        return this.http.get(`${this.uri}`);
    }

    getRug(id: number) {
        ...
        return this.http.get(`${this.uri}/${id}`);
    }
    ...
    deleteRug(id: number) {
        return this.http.get(`${this.uri}/${id}/delete`);
    }

   ...
}

...

app.use('/rugs', rugRoute);

...

//list
rugRoutes.route('/').get(function (req, res) {
    find(function (err, rugs) {
        if (err) { console.log(err); }
        else { res.json(rugs); }
    });
});

//details
rugRoutes.route('/:id').get(function (req, res) {
    let id = req.params.id;
    findById(id, function (err, rug) {
        res.json(rug);
    });
});

//add
rugRoutes.route('/0/edit').post(function (req, res) {
    let rug = new Rug(req.body);
    rug.save().then(
        () => { res.status(200).json({ 'rug': 'Rug added successfully' }); })
        .catch(err => { res.status(400).send("Unable to save to database"); });
});

...

const routes: Routes = [
  { path: 'rug-list', component: RugListComponent },
  { path: 'rug-list/:id', component: RugDetailComponent },
  { path: 'rug-list/:id/edit', component: RugEditComponent },
  { path: '**', component: HomeComponent, pathMatch: 'full' },
];