1
GET /contact 200 33ms - 2.26kb
GET /stylesheets/bootstrap.css 304 2ms
GET /stylesheets/header.css 304 1ms
GET /stylesheets/style.css 304 2ms  
GET /stylesheets/contact.css 304 1ms
GET /javascripts/script.js 404 1ms

It keeps saying 404 when I try to load my javascript file. I have no idea why this is not working!

here are the lines that include the script:

extends layout
block css
  link(rel='stylesheet', href='/stylesheets/contact.css')
  script(type="text/javascript", src='/javascripts/script.js')

the css is loading fine. here is the beginning of the script file:

$(window).load(function() {
  function() {
    console.log("inside basil script");

so it is definitely not working.

Why could this be happening? I know it is very simple but I can't figure it out. I just started using node.js

PS here is my app.js file (well part of it)

// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
1
  • Where is your server side code, which serves static files from node? Commented Oct 13, 2013 at 22:14

3 Answers 3

2

Do you use the http://www.senchalabs.org/connect/static.html middleware in your application to serve directory with clien side javascripts? (i am 90% sure that you use expressJS framework).

Sign up to request clarification or add additional context in comments.

2 Comments

yeah I am using expressJS. is that the problem?
place all css and client side javascripts in public directory so it looks like this ``` /public/ /stylesheets/contact.css /javascripts/script.js ```
2

Looking at the http codes you showed, I belive you only added one directory to serve static files and not added javascripts one.

so you have something like

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

now you need to add

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

Comments

0

Instead of

app.use(express.static(path.join(__dirname, 'public')));

use

app.use(express.static('public'));

It's work for me

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.