So I am trying to write a simple node server that will fetch a very simple html file when it is hit with a get request at the root directory. Everything works fine until I try to attach a javascript file to my html file, then I get hit with the error Uncaught SyntaxError: Unexpected token <
I have realized that this is just a 404 error, but I am completely unable to figure out how to make this stop happening.
test.html
<!DOCTYPE html>
<html>
<head>
<title>title</title>
</head>
<body>
<script type = "text/javascript" src = "/home/danny/Documents/Application/server/test.js"> </script>
booya
</body>
</html>
app.js
/**
* Main application file
*/
'use strict';
var express = require('express');
var mongoose = require('mongoose');
var tweet = require('../models/tweet.js');
// Connect to database
mongoose.connect('mongodb://localhost/test');
// Setup server
var express = require('express');
var app = express();
require('./config/express');
require('./routes')(app);
app.engine('html', require('ejs').renderFile);
var server = require('http').createServer(app);
// Start server
server.listen(3000, function() {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
console.log(__filename);
// Expose app
exports = module.exports = app;
routes.js
/**
* Main application routes
*/
'use strict';
module.exports = function(app) {
// Insert routes below
app.route('/aa')
.get(function(req, res) {
res.sendFile('/home/danny/Documents/Application/server/test.js')
})
// All other routes should redirect to the index.html
app.route('/*')
.get(function(req, res) {
// res.set('Content-Type', 'text/html');
res.render('/home/danny/Documents/Application/src/test.html');
});
};
Anybody have any ideas why it is unable to find the file?