How to use Node.js to build pages that are a mix between static and dynamic content?

前端 未结 7 1090
隐瞒了意图╮
隐瞒了意图╮ 2020-12-07 23:02

All pages on my 5 page site should be output using a Node.js server.

Most of the page content is static. At the bottom of each page, there is a bit of dynamic conten

7条回答
  •  情话喂你
    2020-12-07 23:35

    One of the best things I found is to use NodeJS, Express and Mustache...

    You can create your HTML pages as you normally would using Mustache syntax for placeholders for your variables {{name}}...

    When a user hits your site, express routs the slug to the correct template... NodeJS get's the file... NodeJS get's the dataset from a DB... Run it through Mustache on the server... Send the completed page to the client...

    Here is a scaled back version I wrote on my blog. It's simple but the idea is pretty sound. I use it to quickly deploy pages on my site.

    http://devcrapshoot.com/javascript/nodejs-expressjs-and-mustachejs-template-engine

    I went this route because I didn't want to learn all of the extra syntax to write a language I already knew (html). It makes more sense and follows more of a true MVC pattern.

提交回复
热议问题