跳到主要内容
CNode

如何引用我建的JS文件?

社区
Jjewel发布于 14 年前最后回复 14 年前
159740

目录结构


images
    style.css
    .......
js
    jquery.min.js
    index.js
node_modules
    socket.io
index.html
server.js

我在index.html 里写的

都无效,请问是server.js里还需要怎么配置下吗?
查看回复

回复 (1)

H
haiyupeter#114 年前

需要自己读文件流,然后返回 :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/');

访问链接:http://127.0.0.1:9337/

参与回复

登录后即可参与回复。登录