I'm trying to learn how to create a REST API, I'm new to this concept and when I ran my aplication on ny LocalHost it retur the
TypeError: Genre.getGenres is not a function" error.
I have Already trie changing the code so it looks like my genre.js model, but it keeps giving me back the same error.
// app.js code
// здесь я добавил из genre.js в app.js
Жанр = требуется ('./ models / genres');
Жанр = требуется ('./ models / books');
//Connect to Mongoose
mongoose.connect('mongodb://localhost/bookstore');
var db = mongoose.connection;
//error is coming from here
app.get('/api/genres', function(req, res){
Genre.getGenres(function(err, genres){
if(err){
throw err;
}
res.json(genres);
});
});
// genres.js code:
var mongoose = require('mongoose');
//Genre Schema
var genreSchema = mongoose.Schema({
name:{
type: String,
required: true
},
create_date:{
type: Date,
default: Date.now
}
});
var Genre = module.exports = mongoose.model('Genre', genreSchema);
// Get Genres
module.exports.getGenres = function(callback, limit){
Genre.find(callback).limit(limit);
}
Ожидается, что приложение вернет полный список JSON раздела жанров базы данных.