Tuesday, March 20, 2018

express pug materialize, router



=============== every time, save file, re-START server ==============
nodemon --exec npm start


npm install express-generator -g

express --view=pug myapp

nodemon can monitor file change and restart server
npm install -g nodemon



with express-pug,  normally start server by
npm start
with Nodemon installed, I use
nodemon --exec npm start
Note: nodemon app.js will NOT work here,
because express.js use start script


============================================================


Pug.js Cheat Sheet



https://codepen.io/mimoduo/post/pug-js-cheat-sheet



Includes

//- Include another pug file
include ./path-to/file.pug

//- Include other file types as plain text
include styles.css
include script.js

#Extends & Blocks

//- template.pug
block data
  - var pageTitle = "Pugcupid"
html
  head
    title= pageTitle
  body
    block ribbon
    block content
      p Pugs fo life
//- page.pug
//- Extends template.pug
extends ./path-to/template.pug

block data
  - var pageTitle = "Pudome"

block ribbon
  p New pug jazz

block content
  p This wipes out "Pugs fo life"



========================================================

http://localhost:3000/index/tmp2/laxxxx/2


var index = require('./routes/index');


app.use('/index', index);


// this is index router, should continue with /index/xxxxxxxxx, not duplicate
// wrong : router.get('/index/:template/:place/:url_id', function(req, res, next) {
router.get('/:template/:place/:url_id', function(req, res, next) {

No comments: