So I'm trying to insert 3 strings from postman to my mongo database using the api localhost:3000/api/comment/
my database is on mongodb://localhost:27017/commentbox
and my server.js contains
var express = require('express');
var morgan = require('morgan');
var bodyParser = require('body-parser');
var config = require('./config');
var mongoose = require('mongoose');
var app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(morgan('dev'));
var api = require("./app/routes/api")(app, express);
api.use('/api', api);
app.get('*',(req, res)=>{
res.sendFile(__dirname + '/public/views/index.html');
});
mongoose.connect(config.database, { useNewUrlParser: true },(err)=>{
if(err){
console.log(err);
}else{
console.log('Connected to DB');
}
});
app.listen(config.port, (err) =>{
if(err){
console.log(err);
}else{
console.log('Listening on port:'+ config.port);
}
});
and this is the code for my api.js
var User = require('../models/user');
module.exports = function(app,express){
var api = express.Router();
api.post('/comment', function(req,res){
var user = new User({
name: req.body.name,
comment: req.body.comment,
date: req.body.date
});
user.save(function(err){
if(err){
res.send(err);
return;
}
res.json({ message: "User has commented"});
});
});
return api;
}
when I try to post on postman with name, comment, date (btw this are 3 strings at the moment) I always got error 404
what should be the problem? I have followed the guide thoroughly