节点挂在mongoose的动作上

所以我正在用Mongoose和Node开发一个应用程序。 每当我尝试使用邮递员得到/api/users或后/api/users/name/name/email/test它只是挂起。 我已经确认它连接到数据库, app.listen()db.once('open')

这是我的model.js

 'use strict' var mongoose = require('mongoose'); var Schema = mongoose.Schema; const userSchema = new Schema({ first_name : String, last_name : String, email : { type : String, unique : true }, password : String, age : String, address : String, phoneNumber: String, gender : String, preffered : String, alerts : Array }); module.exports = mongoose.model('User', userSchema) 

这是我的controller.js

 const User = require('../models/user'); module.exports = { getAllUsers: (req, res) => { User.find({}, (err, user) => { if(err) {res.send(err)} console.log('test'); res.status(200).json(user); }); }, createUser: (req, res) => { var newUser = new User(); newUser.first_name = req.params.fn; newUser.last_name = req.params.ln; newUser.email = req.params.em; newUser.password = req.params.pw; newUser.save((err, user) => { if(err){res.send(err)} console.log(newUser.first_name + ' Created'); res.json(user); mongoose.connection.close(); }); }, readUser: (req, res) => { User.findOne({_id: req.params.id}, (err, user) => { if(err){res.send(err)} res.json(user) }); }, updateUser: (req, res) => { User.findOneAndUpdate({_id: req.params.id}, req.body, {new: true}, (err, user) => { if(err){res.send(err)} res.json(user); }); }, removeUser: (req, res) => { User.remove({_id: req.params.id}, (err, user) => { if(err){res.send(err)} res.json("User was succesfully deleted"); }); } } 

这是我的routes.js

 const express = require('express'), router = express.Router(), apiController = require('./controllers/api.controller' ), mainController = require('./controllers/main.controller' ), profileController = require('./controllers/profile.controller'), adminController = require('./controllers/admin.controller' ); module.exports = router; //Handled by apiController router.get('/api/users', apiController.getAllUsers); router.post('/api/:fn/:ln/:em/:pw/', apiController.createUser); router.route('/api/:id') .get(apiController.readUser) .put(apiController.updateUser) .delete(apiController.removeUser); 

       

网上收集的解决方案 "节点挂在mongoose的动作上"