将更多html页面添加到节点服务器

时间:2016-01-24 23:18:24

标签: javascript html ajax node.js

我想添加另一个html页面,我可以路由到con并读取temp,就像我在index.html中一样

    var http = require('http');
var ejs = require('ejs');
var fs = require('fs');
var system = require('child_process').exec;



var content = fs.readFileSync('index.html', 'utf-8');
var compiled = ejs.compile(content);
http.createServer(function(req,res) {
      var temp = 5;

     if(req.url === "/con") {
          console.log("You are in con");
    }
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.end(compiled({temp: temp}));
}).listen(8080);

0 个答案:

没有答案