Loading basic HTML in Node.js

后端 未结 20 1335
暗喜
暗喜 2020-11-28 17:34

I\'m trying to find out how to load and render a basic HTML file so I don\'t have to write code like:

response.write(\'...

blahblahblah

...\
20条回答
  •  攒了一身酷
    2020-11-28 18:06

    I know this is an old question, but as no one has mentioned it I thought it was worth adding:

    If you literally want to serve static content (say an 'about' page, image, css, etc) you can use one of the static content serving modules, for example node-static. (There's others that may be better/worse - try search.npmjs.org.) With a little bit of pre-processing you can then filter dynamic pages from static and send them to the right request handler.

提交回复
热议问题