Created
September 17, 2014 20:03
-
-
Save 007lva/23983d4b1a5dfb7d07c3 to your computer and use it in GitHub Desktop.
server.js
This file contains hidden or 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
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; | |
}; |
This file contains hidden or 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 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