Nathan
Nathan

Reputation: 350

Server not finding files

I have written a simple express script to serve a webpage with embedded javascript. However, the server can't seem to find any of the files that I am giving to it. What's more frustrating, sometimes it seems to work, only for it to break again when I change an irrelevant bit of code.

All of the files are where I am telling the script, but I constantly get the following kind of error:

GET http://localhost:55154/jsPsych/jspsych.js net::ERR_ABORTED 404 (Not Found)

Here is the express code:

// --- LOADING MODULES
var express = require('express');

// --- INSTANTIATE THE APP
var app = express();

// --- STATIC MIDDLEWARE 
app.use(express.static(__dirname + '/public'));
app.use('jsPsych', express.static(__dirname + "/jsPsych"));

// --- VIEW LOCATION, SET UP SERVING STATIC HTML
app.set('views', __dirname + '/public/views');
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');

// --- ROUTING
app.get('/', function(request, response) {
    response.render('index.html');
});

app.get('/experiment', function(request, response) {
    response.render('go_no_go.html');
});

// --- START THE SERVER 
var server = app.listen(process.env.PORT, function(){
    console.log("Listening on port %d", server.address().port);
});

And here is the relevant bit of javascript:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">

    <script type="text/javascript" src="../jsPsych/jspsych.js"></script>
    <link type= "text/html" href="jsPsych/css/jspsych.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="jsPsych/plugins/jspsych-html-keyboard-response.js"></script>
    <script type="text/javascript" src="jsPsych/plugins/jspsych-image-keyboard-response.js"></script>
    <script type="text/javascript" src="jsPsych/plugins/jspsych-survey-text.js"></script>
    <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
  </head>

Upvotes: 3

Views: 762

Answers (1)

Jon dreisbach
Jon dreisbach

Reputation: 206

do you have to move up a directory to access jspsych.js? if not remove the ".." in your relative path to make sure that the relative path lines up with your files.

Upvotes: 2

Related Questions