-
-
Save azamsharp/c17cd38cfaf50fb64097dfb533901555 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
const express = require('express') | |
const app = express() | |
const mustacheExpress = require('mustache-express') | |
// initialize pg promise library | |
const pgp = require('pg-promise')() | |
// location of the database | |
const connectionString = "postgres://localhost:5432/tripsdb" | |
// create a db object based on the connection string | |
const db = pgp(connectionString) | |
// tell express to use mustache templating engine | |
app.engine('mustache',mustacheExpress()) | |
// the pages are located in views directory | |
app.set('views','./views') | |
// extension will be .mustache | |
app.set('view engine','mustache') | |
// display all trips | |
app.get('/trips',(req,res) => { | |
// access the database | |
db.any('SELECT trip_id,name from trips;').then(results => { | |
res.render('index',{trips: results}) | |
}) | |
}) | |
app.listen(3000,() => { | |
console.log('Server is running...') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment