0

I'm having a small problem with my project. I'm using node and express for a little webpage .. it is rendering the html page, but the javascript file (test.js) is not sent to the user ..

<!doctype html>
<html>
    <head>
        <title>Spektrum</title>
        <script src="test.js"></script>
        <meta name = "viewport" content = "initial-scale = 1, user-scalable = no">
        <style>
            canvas{     

            }
        </style>
    </head>
    <body>    
        <!-- some stuff --> 
        </body> 
</html>  

Node.js file:

var http = require('http'),  
    fs = require('fs'),
    express = require('express'), 
    app     = express(); 
    app.use(express.bodyParser());
    app.set('view engine', 'ejs');
    app.engine('html', require('ejs').renderFile);

// ..... 
    app.listen(8080, function() {
  console.log('Server running at http://127.0.0.1:8080/');
}); 

Any idea how to send the javascript file with the html file to the user?

Greetings, JS

1

1 Answer 1

3

you need to use static middleware to serve file (test.js needs to exist)

example:

// GET /javascripts/jquery.js
// GET /style.css
// GET /favicon.ico
app.use(express.static(__dirname + '/public'));
Sign up to request clarification or add additional context in comments.

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.