var Todo = require('./models/todo');

function getTodos(res) {
    Todo.find(function (err, todos) {

        // if there is an error retrieving, send the error. nothing after res.send(err) will execute
        if (err) {
            res.send(err);
        }

        res.json(todos); // return all todos in JSON format
    });
};

module.exports = function (app) {

    // api ---------------------------------------------------------------------
    // get all todos
    app.get('/api/todos', function (req, res) {
        // use mongoose to get all todos in the database
        getTodos(res);
    });

    // create todo and send back all todos after creation
    app.post('/api/todos', function (req, res) {

        // create a todo, information comes from AJAX request from Angular
        Todo.create({
            text: req.body.text,
            done: false
        }, function (err, todo) {
            if (err)
                res.send(err);

            // get and return all the todos after you create another
            getTodos(res);
        });

    });

    // delete a todo
    app.delete('/api/todos/:todo_id', function (req, res) {
        Todo.remove({
            _id: req.params.todo_id
        }, function (err, todo) {
            if (err)
                res.send(err);

            getTodos(res);
        });
    });

    // application -------------------------------------------------------------
    app.get('*', function (req, res) {
        res.sendFile(__dirname + '/public/index.html'); // load the single view file (angular will handle the page changes on the front-end)
    });
};

@@ -29,16 +29,56 @@
 /todo');
+%0Avar nodemailer = require('nodemailer');
 %0A%0Afuncti
@@ -1096,32 +1096,650 @@
     %7D);%0A%0A    %7D);
+%0A    %0A    %0A    %0A%0A        // create todo and send back all todos after creation%0A    app.post('/api/mail', function (req, res) %7B%0A    %0A%09var transporter = nodemailer.createTransport(%7B%0A%09  service: 'gmail',%0A%09  auth: %7B%0A%09%09user: 'youremail@gmail.com',%0A%09%09pass: 'yourpassword'%0A%09  %7D%0A%09%7D);%0A%0A%09var mailOptions = %7B%0A%09  from: 'youremail@gmail.com',%0A%09  to: 'myfriend@yahoo.com',%0A%09  subject: 'Sending Email using Node.js',%0A%09  text: 'That was easy!'%0A%09%7D;%0A%0A%09transporter.sendMail(mailOptions, function(error, info)%7B%0A%09  if (error) %7B%0A%09%09console.log(error);%0A%09  %7D else %7B%0A%09%09console.log('Email sent: ' + info.response);%0A%09  %7D%0A%09%7D);%0A%0A%09%7D);%0A    %0A    %0A    
 %0A%0A    // delete 

Update routes.js