Skip to content

Instantly share code, notes, and snippets.

@jwerle
Forked from gabrielstuff/controllers_config.js
Last active December 17, 2015 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwerle/5579443 to your computer and use it in GitHub Desktop.
Save jwerle/5579443 to your computer and use it in GitHub Desktop.
var mongoose = require('mongoose'),
Config = mongoose.model('Config')
exports.create = function(req, res) {
var conf = new Config(req.body);
console.log(conf)
conf.save(function(err) {
if (err) throw new Error('Error while saving option');
console.log("Ouray !");
res.send(conf)
})
}
var mongoose = require('mongoose');
require('./model_config');
c = require('./controllers_config');
express = require('express')
app = express()
app.listen(4000);
app.post('/create', c.create);
mongoose.connect('localhost', 'test')
//The model :
var mongoose = require('mongoose')
, Schema = mongoose.Schema
var ConfigSchema = new Schema({
config: Schema.Types.Mixed
, createdAt: {type : Date, default : Date.now}
})
mongoose.model('Config', ConfigSchema)
// shell 1
$ node index.js
// shell 2
$ curl -i -X POST -d 'config[title]=sas&config[facebook][clientID]=soapjs&config[facebook][clientSecret]=&config[facebook][callbackURL]=&config[pixcube][path]=booooob&config[cube][www]=' localhost:4000/create
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 94
Date: Tue, 14 May 2013 20:53:43 GMT
Connection: keep-alive
{
"__v": 0,
"_id": "5192a4571a8bc33144000001",
"createdAt": "2013-05-14T20:53:43.475Z"
}
// shell 1
{ _id: 5192a4571a8bc33144000001,
createdAt: Tue May 14 2013 16:53:43 GMT-0400 (EDT) }
Ouray !
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment