Skip to content

Instantly share code, notes, and snippets.

@anefzaoui
Created October 22, 2024 11:15
Show Gist options
  • Select an option

  • Save anefzaoui/12eef40e78aaa62e3043f2fe8a737c22 to your computer and use it in GitHub Desktop.

Select an option

Save anefzaoui/12eef40e78aaa62e3043f2fe8a737c22 to your computer and use it in GitHub Desktop.
// 1- les appels des modules/packages/librairies
const express = require('express');
const mysql = require('mysql');
const app = express();
const path = require('path');
var hbs = require('express-hbs');
var port = 3000;
// 2- configuration
var connection = mysql.createConnection(
{
host: "localhost",
user: "root",
password: "",
database: "isetcert"
}
)
connection.connect();
app.engine('hbs', hbs.express4({
partialsDir: __dirname + '/views/partials',
layoutsDir: __dirname + '/views/layouts',
}));
app.set('view engine', 'hbs');
app.set('views', __dirname + '/views');
// 3- les routes
app.get("/", function (req, res) {
var sql = "select * from cert"
connection.query(sql, function (error, results) {
console.log(results)
res.render("index", {
layout: "main"
})
})
})
// 4- démarrer le serveur
app.listen(port);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment