This work is produced by Mats Loock for the course Server-based Web Programming (1DV023) at Linnaeus University.
All content in this work excluding photographs, icons, picture of course literature and Linnaeus University logotype and symbol, is licensed under a
Creative Commons Attribution 4.0 International License.
If you change the content do not use the photographs, icons, picture of the course literature or Linnaeus University logotype and symbol in your new work!
At all times you must give credit to: ”Linnaeus university – Server-based Web Programming (1DV023)” with the link https://coursepress.lnu.se/kurs/serverbaserad-webbprogrammering/ and to the Creative Common-license above.
During the course we will use...
app.js
is the applications entry point.routes/
directory.controllers/
directory.views/
directory.public/
directory.express
express-hbs
moment
morgan
nodemon
(req, res, next))
.(err, req, res, next))
.express.static
, express.urlencoded
router.get()
and router.post()
methods are two routing functions in Express.router
object as an argument to app.use()
.
app.use('/', require('./routes/homeRouter'))
http://localhost:8000/app.use('/home', require('./routes/homeRouter'))
http://localhost:8000/homeres.render(view [, locals])
renders a view and sends the HTML string to the client.
view
, the path of the view file to render.locals
(optional), an object that contains data (viewData) to pass from the controller to the view.npm install express-hbs
.hbs
for extensions and find layouts in views/layouts
.