﻿var express = require('express');
var app = express();
var mongoose = require('mongoose');
var morgan = require('morgan');
var bodyParser = require('body-parser');    // pull information from HTML POST (express4)
var methodOverride = require('method-override'); // simulate DELETE and PUT (express4)


mongoose.connect('mongodb://localhost/todo');

app.use(express.static(__dirname + '/public'));
app.use(morgan('dev'));
app.use(bodyParser.urlencoded({ 'extended': 'true' }));         // parse application/x-www-form-urlencoded
app.use(bodyParser.json());                                     // parse application/json
app.use(bodyParser.json({ type: 'application/vnd.api+json' })); // parse application/vnd.api+json as json
app.use(methodOverride());

app.get('/', function (req, res) {
    console.log('Get /');
    res.send('Get /');
});

app.get('/todo', function (req, res) {
    console.log('Get todo');
    res.send('Get todo');
});

var server = app.listen(8080, function () {
    console.log("App listening on port 8080");
});

@@ -742,24 +742,379 @@
 erride());%0A%0A
+app.get('/api/todos', function (req, res) %7B%0A%0A    // use mongoose to get all todos in the database%0A    Todo.find(function (err, todos) %7B%0A%0A        // if there is an error retrieving, send the error. nothing after res.send(err) will execute%0A        if (err)%0A            res.send(err)%0A%0A        res.json(todos); // return all todos in JSON format%0A    %7D);%0A%7D);%0A%0A
 app.get('/',
@@ -1288,16 +1288,111 @@
 ');%0A%7D);%0A
+// define tables%0A%0Avar Todo = mongoose.model('Todo', %7B%0A    text: String%0A%7D);%0A%0A%0A// starting server
 %0Avar ser

add get api todos