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>
../jsPsychin the first<script>tag then./jsPsychin the following ones? Where should thejsPsychdirectory be located on the disk? Should it be at the same level as your server script? Or maybe underpublic? Maybe somewhere else?app.use('jsPsych', ...)beapp.use('/jsPsych', ...)?app.use('/jsPsych', ...),http://localhost:55154/jsPsych/jspsych.jsretrieves the file namedjspsych.jsunder the directoryjsPsychat the same level as the server script.