Skip to content

Instantly share code, notes, and snippets.

@atimermann
Created August 29, 2015 18:00
Show Gist options
  • Save atimermann/5e8191f13e3718a60d25 to your computer and use it in GitHub Desktop.
Save atimermann/5e8191f13e3718a60d25 to your computer and use it in GitHub Desktop.
var express = require('express');
var app = express();
app.use('/static', express.static('static'));
app.use(function (req, res, next) {
console.log('Time:', Date.now());
next();
});
app.engine('html', require('hogan-express'));
app.set('view engine', 'html');
app.get('/', function (req, res) {
var dados = {
partials: {header: 'header'},
name: "André Timermann",
foto: "foto.jpg",
desc: "<p> Isto é uma Descrição </p>",
filhos: [
{nome: 'João'},
{nome: 'Maria'}
]
};
res.render('index', dados);
});
app.get('/leandro', function (req, res) {
res.json({nome: 'Leandro', idade: 29});
});
/********************************************************
* Base de Dados
*
********************************************************/
// ----------------------------------------
// INICIALIZA BANCO DE DADOS
// ----------------------------------------
var knex = require('knex')({
client: 'sqlite3',
connection: {
filename: "./mydb.sqlite"
}
});
app.get('/db_create', function(req, res){
knex.schema.createTable('usuarios', function(table){
table.increments();
table.string('nome');
table.timestamps();
}).then(function(){
res.json(true);
}.catch(function(error){
res.json(error);
});
});
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment