Mongoose没有定义错误

时间:2018-05-04 05:21:51

标签: mongoose undefined

我刚从节点中的apis开始,我遇到了错误。当我尝试访问“http://localhost:3000/”时,我收到错误“无法访问网站”。这篇文章也附有Nodemon错误。

这是app.js

var express=require('express');
var app=express();
var bodyParser=require('body-parser');
var mongoose=require('mongoose');
mongoose.connect('mongodb://localhost/arys');

 Employee=require('./models/employee');
//connect to mongoose
var db=mongoose.connection;

app.get('/',function(req,res){

    res.send('Use API endpointsdsfs');
});

app.get('/api/employees',function(req,res){

    Employee.getGenres((err, employees) => {
        if(err){
            throw err;
        }
        res.json(emplyees);
    });
});

app.listen(3000);
console.log('Running on Port 3000');

这是models / employee.js

const mongooose=require('mongoose');



//Employee Schema

const employeeSchema=mongoose.Schema({

   name:{
    type:String,
    required:true
   },
   email:{
   type:String,
   required:true

   }
});

const Employee=module.exports=mongoose.model('Employee',employeeSchema);


//get Employees
module.exports.getEmployees= (callback, limit) =>
{

Employees.find(callback).limit(limit);
}

enter image description here

0 个答案:

没有答案