Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
dynamic-websites/exercises/12_spa/books/index.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
39 lines (31 sloc)
863 Bytes
This file contains 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
#!/usr/bin/env node | |
'use strict' | |
const express = require('express') | |
const es6Renderer = require('express-es6-template-engine') | |
const bodyParser = require('body-parser') | |
const app = express() | |
app.use(express.static('public')) | |
app.use(bodyParser.urlencoded({ extended: true })) | |
app.engine('html', es6Renderer) | |
app.set('views', 'html') | |
app.set('view engine', 'html') | |
const books = require('./modules/books') | |
const port = 8080 | |
// const status = { | |
// ok: 200, | |
// created: 201, | |
// notFound: 404, | |
// notAcceptable: 406, | |
// conflict: 409 | |
// } | |
app.get('/', async(req, res) => { | |
try { | |
console.log(`query ${req.query.q}`) | |
const bookList = await books.search(req) | |
console.log(bookList) | |
res.render('index', {locals: {books: bookList}}) | |
} catch(err) { | |
console.log(err.message) | |
} | |
}) | |
app.listen(port, () => console.log(`app listening on port ${port}`)) |