Skip to content

Instantly share code, notes, and snippets.

@007lva 007lva/cursos.js
Created Sep 17, 2014

Embed
What would you like to do?
server.js
module.exports = function(cursos, database){
cursos.get("/", function(req, res, next){
console.log("FUNCIONA");
database.getConnection(function(err, connection){
connection.query("select * from curso", function(err, rows){
console.log(JSON.stringify(rows));
res.send(rows);
});
});
});
cursos.post("/", function(req, res, next){
database.getConnection(function(err, connection){
connection.query("select max(codigocurso) from curso", function(err, rows){
var maxId = rows[0]["max(codigocurso)"];
var curso = {codigocurso: maxId + 1, nombrecurso: "Geometria"};
connection.query("insert into curso set ?", curso, function(err, result){
console.log(JSON.stringify(result));
res.send(result);
});
});
connection.release();
});
});
return cursos;
};
var express = require("express");
var app = express();
var mysql = require("mysql");
var config = require("./config/dbconfig");
console.log(config.mensaje);
var database = mysql.createPool(config.db);
//app.use(bodyParser.urlencoded({ extended: true }));
//app.use(bodyParser.json());
//var port = 8000;
var cursos = express.Router();
app.use("/cursos", require("./routes/cursos")(cursos, database));
app.listen(8000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.