admin管理员组文章数量:1418435
I'm creating a chat, using server Express
of NodeJS
and AngularJS
for manager in client side
But when I try include /js/code.js
in my html
, it can not found, because is not routed by Express
<!-- my include in html -->
<script src="./js/code.js"></script> <!- this is not found in execution -->
Meu index.js:
var app = require('express')();
var http = require('http').Server(app);
var io = require("socket.io")(http);
app.get('/', function(request, response){
response.sendFile(__dirname + '/index.html');
});
How to can I fix this problem, without route all js file I will using in my project or routing all js file in path a lot?
I'm creating a chat, using server Express
of NodeJS
and AngularJS
for manager in client side
But when I try include /js/code.js
in my html
, it can not found, because is not routed by Express
<!-- my include in html -->
<script src="./js/code.js"></script> <!- this is not found in execution -->
Meu index.js:
var app = require('express')();
var http = require('http').Server(app);
var io = require("socket.io")(http);
app.get('/', function(request, response){
response.sendFile(__dirname + '/index.html');
});
How to can I fix this problem, without route all js file I will using in my project or routing all js file in path a lot?
Share Improve this question edited Jan 30, 2015 at 11:32 Lai32290 asked Jan 30, 2015 at 11:26 Lai32290Lai32290 8,60819 gold badges70 silver badges104 bronze badges1 Answer
Reset to default 5Use app.use to specify your public files to your node app, like below
app.use(express.static(yourPublicPath));
EDIT:
You are getting "Express undefined" error because it is not defined. You can easily fix this by defining your app in 2 stages:-
var express = require('express');
var app = express();
On a side note, I would strongly remend to go through Expressjs docs to learn more about Express.
本文标签: javascriptHow to include JS file in HTMLusing NodeJS Express serverStack Overflow
版权声明:本文标题:javascript - How to include JS file in HTML, using NodeJS Express server? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745279826a2651370.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论