0

Im attempting to serve files with the assistance of express.static and am having difficulty getting it to work.

My code includes the following:

var app             = express();
app.use(express.static(__dirname + '/public'));
var app_router = express.Router();

    app_router.get('/', function(req, res){
        res.sendfile('/test.html');
    });

app.use('/', app_router);

This does not function in serving test.html, however if I replace it with ./public/test.html it is served correctly(Basically bypassing express.static)

Any assistance would be appreciated. Ive looked around and found code similar to mine that appears to be working however I must be missing something relatively simple and would appreciate another set of eyes. Thanks!

1 Answer 1

1

You're misunderstanding express.static().

res.sendFile() takes a path to a file on disk, and has nothing to do with express.static().

express.static() handles requests to paths matching files in the folder you pass it.

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

1 Comment

Ah, ok. Yes totall misunderstanding on my part there. Thank you!

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.