我刚从节点中的apis开始,我遇到了错误。当我尝试访问“http://localhost:3000/”时,我收到错误“无法访问网站”。这篇文章也附有Nodemon错误。
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');
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);
}