Advertisement
Mrgentledolphin

CODE

Sep 25th, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const express = require("express");
  2. const knex = require("knex");
  3. const bodyParser = require("body-parser");
  4.  
  5. const staticAssets = __dirname + "/public";
  6.  
  7. const db = knex({
  8.     client: "mysql",
  9.     connection: {
  10.         host: "127.0.0.1",
  11.         user: "root",
  12.         database: "testing-app"
  13.     }
  14. })
  15.  
  16.  
  17.  
  18. express()
  19.     .use(bodyParser.json())
  20.     .set("view engine", "hjs")
  21.     .use(express.static(staticAssets))
  22.  
  23.     .get("/", (req, res, next) => {
  24.         db("users").then((users) => {
  25.             res.render("users", {
  26.                 title: "All Users",
  27.                 users: users,
  28.             })
  29.         })
  30.     })
  31.  
  32.     .get("/viewtweets/:user_id", (req, res, next) => {
  33.         db("tweets").then((tweets) => {
  34.             res.render("tweets", {
  35.                 title: "My tweets",
  36.                 tweets
  37.             })
  38.         })
  39.     })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement