Reputation: 43
My index.html file is like shown below
<html>
<body>
<script src="public/jquery-latest-min.js"></script>
/*But this script file is not importing and creating error */
</body>
</html>
app.js code is
var express = require('express'),
app = express(),
server = require('http').createServer(app),
io = require('socket.io').listen(server);
server.listen(3000);
app.get('/',function(req, res){
res.sendfile(__dirname + '/index.html');
});
How can the index.html file can serve the jquery file located in public folder.
And my project structure is:
|-index.html
|-app.js
|-public/jquery-latest-min.js
Upvotes: 0
Views: 1783
Reputation: 731
You can configure static files as per @anubhav suggested.
Then you can reference your files like below.
<script src="jquery-latest-min.js"></script>
You should not use absolute path rather just to reference path which are relative to static folders like public in your case.
Upvotes: 0
Reputation: 7208
The following can be used to serve static files such as javascript files or CSS files.
var server = express(); // better instead
server.use(express.static(__dirname + '/public'));
Upvotes: 1