相关疑难解决方法(0)

如何使用Node.js构建静态和动态内容混合的页面?

我的5页网站上的所有页面都应该使用Node.js服务器输出.

大多数页面内容都是静态的.在每个页面的底部,都有一些动态内容.

我的node.js代码目前看起来像:

var http = require('http'); 

http.createServer(function (request, response) {

    console.log('request starting...');

    response.writeHead(200, { 'Content-Type': 'text/html' });

    var html = '<!DOCTYPE html><html><head><title>My Title</title></head><body>';
    html += 'Some more static content';
    html += 'Some more static content';
    html += 'Some more static content';
    html += 'Some dynamic content';
    html += '</body></html>';

    response.end(html, 'utf-8');

}).listen(38316);
Run Code Online (Sandbox Code Playgroud)

我确信这个例子有很多不妥之处.请赐教!例如:

  • 如何将静态内容添加到页面而不将其作为变量值存储在字符串中+ =多次?
  • 在Node.js中构建小型站点的最佳实践方法是什么,其中所有页面都是静态和动态内容的混合?

node.js

39
推荐指数
3
解决办法
6万
查看次数

标签 统计

node.js ×1