<file_sep>var express = require('express');
var router = express.Router();
var db = require('../db/db')

/* GET home page. */
router.post('/eliminar', function (req, res, next) {

    db.eliminar({id:req.body.id}, function (success, cb) {
        console.log(cb)
        res.json({success: success, result: cb})
    })
});

router.post('/editar', function (req, res, next) {
    db.editar({id: req.body.id, texto: req.body.texto}, function (success, cb) {
        console.log(cb)
        res.json({success: success, result: cb})
    })
});

router.get('/todos', function (req, res, next) {
    db.todos({}, function (success, cb) {
        console.log(cb)
            res.json({success: success, result: cb})

    })
});

router.post('/crear', function (req, res, next) {
    db.crear({texto: req.body.texto}, function (success, cb) {
        console.log(cb)
        res.json({success: success, result: cb})
    })
});


module.exports = router;




<file_sep>var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var apiRouter = require('./routes/API');

var os = require('os');


var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hbs');

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/API', apiRouter);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  next(createError(404));
});

// error handler
app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);
  res.render('error');
});

app.listen(app.get('port'), function () {
    console.log('Node app is running on port', app.get('port'));
    var ifaces = os.networkInterfaces();
// console Server ip address
    Object.keys(ifaces).forEach(function (ifname) {
        var alias = 0;
        ifaces[ifname].forEach(function (iface) {
            if ('IPv4' !== iface.family || iface.internal !== false) {
                // skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses
                return;
            }
            if (alias >= 1) {
                // this single interface has multiple ipv4 addresses
                console.log(ifname + ':' + alias + ' ' + iface.address);
            } else {
                // this interface has only one ipv4 adress
                console.log(ifname + ' ' + iface.address);
            }
        });
    });
})

module.exports = app;
