express.js how show image?

node.js

Solution

in your case it is enough to write:

app.use(express.static('public'));

it will serve directly the public folder.

an image in this path `/public/images/somePhoto.png` would be shown like that: `http://localhost:8080/images/somePhoto.png`

source: https://expressjs.com/en/starter/static-files.html

Problem

I have images in /public folder and I want to show them..simply like this: `<img src="a.jpg">` My app.js code ``` var express = require('express') , app = express() , http = require('http') , server = http.createServer(app) , io = require('socket.io').listen(server); server.listen(8080); app.use('/public', express.static(__dirname + "/public")); ``` If I open it in localhost this error is still showing ``` NetworkError: 404 Not Found - http://localhost:8080/public/a.jpg" ```

Original source