Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. var express = require('express');
  2. var router = express.Router();
  3.  
  4. var fs = require("fs");
  5. var file = __dirname+"/"+"database.db";
  6. var exists = fs.existsSync(file);
  7. if(!exists) {
  8. fs.openSync(file, "w");
  9. }
  10.  
  11. var sqlite3 = require('sqlite3').verbose();
  12. var db = new sqlite3.Database(file);
  13.  
  14. /* GET home page. */
  15. router.get('/', function(req, res, next) {
  16. res.render('index', { title: 'Express' });
  17. });
  18.  
  19. router.get('/info/:id', function(req, res, next) {
  20. res.render('testmc', {
  21. title: req.params.id,
  22. imgSrc: "../images/the%20hitchhiker_s%20guide%20to%20the%20galaxy%20book%20cover.jpg",
  23. imgAlt: "Cover of the Hitchhiker's Guide to the Galaxy book.",
  24. bookSummary: "The Hitchhiker's Guide to the Galaxy begins with contractors arriving at Arthur Dent's house, in order to demolish it to make way for a bypass. His friend, Ford Prefect, arrives while Arthur is lying in front of the bulldozers, to stop them from demolishing it. He tries to explain to Arthur that he is actually from a planet somewhere in the vicinity of Betelgeuse and that the Earth is about to be demolished. The Vogons, an alien race, intend to destroy Earth to make way for a hyperspace bypass. The two escape by hitching a lift on one of the Vogons' ships; this is, however, against Vogon regulations and when the pair are discovered, they are tortured with a rendition of Vogon poetry, the third worst in the known Universe, and then thrown into space. They are, very improbably, picked up by the Heart of Gold, a ship powered by an infinite improbability drive, and has been stolen by Ford's semi-cousin and President of the Galaxy, Zaphod Beeblebrox. Zaphod, accompanied by Trillian and the clinically depressed robot Marvin, are searching for the legendary planet of Magrathea.",
  25. price: "12.50",
  26. publisher: "Pan Books",
  27. author: "Douglas Adams",
  28. genre: "Science Fiction"
  29. })
  30. });
  31.  
  32. router.get('/profile/:id', function(req, res, next){
  33. res.render('profile', {
  34. title: "Profile" + req.params.id,
  35. username: req.params.id,
  36. email: "TwanVisser888@zuigt.hard",
  37. password: "hunter888"
  38. })
  39. });
  40.  
  41.  
  42. router.get('/database', function(req, res, next){
  43. db.serialize(function () {
  44. db.each('SELECT book_id as id, title as name FROM book', function (err, row) {
  45. if (err) {
  46. console.log(err);
  47. }
  48. console.log(row.id + "\t" + row.name);
  49. })
  50. });
  51. });
  52.  
  53.  
  54. db.close();
  55. module.exports = router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement