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

前端 未结 7 1087
隐瞒了意图╮
隐瞒了意图╮ 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:31

    A solution have found to this, without using any other modules and or other script is to make the calling script into a module and include it with the function require().
    With this solution I can use javascript which ever way I want
    What I would do is make an ajax call to a nodejs script (www.example.com/path/script.js)
    script.js would need to be built like a module with the exports.functionName=function(){...}
    After that include it in your webserver function require(pathToTheScript).functionName(res,req)
    You will also need to end the response in the functionName(res,req) by doing res.end();

提交回复
热议问题