Serving a static HTML page containing an image using Node JS / Express

佐手、 提交于 2019-11-29 05:06:36

You need to serve your resource files (images, js, css, ...) in a static way.

To do this, put them in a subdirectory, then add this before server.listen

app.use(express.static(__dirname + '/public'));

(Assuming public is the name of the folder containing your static files)

Then, assuming your picture is called logo.png you can call it like this :

<img src="/logo.png" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!