如何引用我建的JS文件?
目录结构 <pre> <code> images style.css … js jquery.min.js index.js node_modules socket.io index.html server.js </code> </pre> 我在index.html 里写的 <script src=“js/jquery.min.js” type=“text/javascript”></script> <script src=“js/index.js” type=“text/javascript”></script> <link href=“images/style.css” rel=“stylesheet” type=“text/css” /> 都无效,请问是server.js里还需要怎么配置下吗?
1 回复
需要自己读文件流,然后返回 :D
var http = require('http');
var url = require('url');
var fs = require('fs');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
var content = fs.readFileSync('index.html');
res.write(content);
res.end();
}).listen(9337);
console.log('Server running at http://127.0.0.1:9337/');