0

I am using Node to render a page when first visited, but for the life of me I cannot get the javascript file to load correctly. It keeps coming up with a 404 error that the test.js file cannot be found. ("GET http://localhost:8080/Include/test.js ") The page loads correctly, but the window.onload javascript event does not fire.

root/helloworld.js

var express = require('express');
var server = require('http').createServer(app);
var app = express();
app.set('views',__dirname+'/views');
app.set('view engine','jade');
app.get('/',function(req,res){
 res.render('index', { title: 'Hey', message: 'Hello!',scripts: [  '/Include/test.js']});
});
app.listen(8080);

root/Include/test.js

window.onload = function () {
    alert('Test Passed');
}

root/views/index.jade

html
  <head>
  -each script in scripts
    script(type='text/javascript', src= script)
    title!= title
    </head>
  body
    h1!= message
  • possible duplicate of [Express-js can't GET my static files, why?](http://stackoverflow.com/questions/5924072/express-js-cant-get-my-static-files-why) – Ben Fortune Apr 12 '15 at 22:39
  • So add this **app.use("/Include/test.js", express.static(__dirname + '/Include/test.js'));** – user3041882 Apr 12 '15 at 23:14

0 Answers0