node.js + express + socket.io cannot load javascript files into index.html

风格不统一 提交于 2019-11-29 15:12:31

If the HTML file is located in the same path as the scripts are, then use relative path like src = "main.js". If it still doesn't work, maybe it's Express' fault.

Add the codes below into your app.js:

app.use(express.static(__dirname + '/scripts'));

And the scripts can be accessed from the path relative to /scripts- e.g. main.js from http://yourdomain/script.js but not from http://yourdomain/scripts/main.js. Sorry for my English.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!