Created
October 22, 2024 11:15
-
-
Save anefzaoui/12eef40e78aaa62e3043f2fe8a737c22 to your computer and use it in GitHub Desktop.
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
| // 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