node.js - Node JS keep getting Failed to load resource error message -


i testing out node.js application , have tried add:

<link rel="stylesheet" href="assets/css/formalize.css" /> <script src="assets/js/jquery.formalize.js"></script>  

to code keeping getting error message:

failed load resource: server responded status of 404 (not found)   http://localhost:3000/assets/css/formalize.css  failed load resource: server responded status of 404 (not found)   http://localhost:3000/assets/js/jquery.formalize.js 

any idea i'm going wrong? here code far (in app.js)

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.htm'); });  io.sockets.on('connection', function(socket) {     socket.on('send message', function(data) {         io.sockets.emit('new message', data);     }); }); 

you need add express.static middleware app , make point directory static assets.

for example, if directory structure set this:

app.js index.htm   static     assets       js         jquery.formalize.js       css         formalize.css 

you specify static asset directory this:

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

and reference files in html file this:

<link rel="stylesheet" href="/assets/css/formalize.css"/> <script src="/assets/js/jquery.formalize.js"></script>  

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -