M
M
Maxim Nine2017-06-21 09:01:30
JavaScript
Maxim Nine, 2017-06-21 09:01:30

How to return a picture (stupid question)?

I'm probably doing it very stupidly, but, having abandoned Apache, I began to transfer my assets using fs, with the following code:

app.get('/assets/css/index.css', function(req, res) {
    fs.readFile('/var/www/assets/css/index.css', function(err, data) {
        res.end(data);
    });
});

And so a question: I need to return the image to the user through res.end. This is how it doesn't work:
app.get('/sources/exit.svg', function(req, res) {
    fs.readFile('/var/www/sources/exit.svg', function(err, data) {
        res.end(data);
    });
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2017-06-21
@kulonful

Don't reinvent the wheel, use express.static()
And it doesn't work most likely because of the wrong (or even missing) Content-Type header

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question