E
E
evgen262015-05-15 01:13:24
Express.js
evgen26, 2015-05-15 01:13:24

How to load images from html img tags ... img tag in nodejs express?

in the file that the server sends the code "hello world, this by img
html is displayed, but the image is not loaded, so if you go to img/img.jpg the image is loaded
var express =require('express');
var app =express(), server;
app.get('/:page?',function(res,req){
req.sendfile(res.params.page);
})
app.listen(3001);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2015-05-15
@k12th

sendfile, emnip, sends a file as an attachment, that is, it forces the browser to download it.
But in general, for statics in express, there is a built-in middleware: expressjs.com/starter/static-files.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question