-
-
Save MrOnlineCoder/fa0155a560d76300413f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var bodyParser = require('body-parser'); | |
var mongoose = require('mongoose'); | |
var app = express(); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({ extended: true })); | |
app.use(express.static(__dirname + '/public')); | |
mongoose.connect('mongodb://localhost:27017'); | |
var kittySchema = mongoose.Schema({ | |
name: String | |
}); | |
var Kitten = mongoose.model('Kitten', kittySchema); | |
app.get("/cats", function(req,res) { | |
Kitten.find().lean().exec(function(err, items) { | |
res.json(items); | |
}); | |
}); | |
var server = app.listen(3000, function () { | |
var host = "127.0.0.1"; | |
var port = server.address().port; | |
console.log('server is listening on http://%s:%s', host, port); | |
var silence = new Kitten({ name: 'Silence' }); | |
silence.save(function(err) { | |
if (!err) { | |
console.log("meow"); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment