Answer the question
In order to leave comments, you need to log in
Why can't I push an object into the database using the post method, with get everything works with a bang?
var express = require('express');
var mongoose = require('mongoose');
mongoose.connect('localhost:/testDb')
var Schema = mongoose.Schema;
var usersSchema = new Schema({name: String});
var User = mongoose.model('users', usersSchema);
var app = express();
app.get('/', function(req,res){
res.send('hello');
})
app.get('/users',function(req, res){
mongoose.model('users').find({}, {_id: false}, function(err, users){
res.send(users);
})
})
app.post('/adduser/:name', function(req, res){ //Не работает пост-метод. С get все отлично
var name = req.params.name;
var user = new User({name: name}).save();
res.send(name + ' was added to DB');
})
var server = app.listen(3030);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question