Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6549096
  • 博文数量: 1159
  • 博客积分: 12444
  • 博客等级: 上将
  • 技术积分: 12570
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-13 21:34
文章分类

全部博文(1159)

文章存档

2016年(126)

2015年(350)

2014年(56)

2013年(91)

2012年(182)

2011年(193)

2010年(138)

2009年(23)

分类: Android平台

2015-07-30 16:04:23

http://stackoverflow.com/questions/17755147/displaying-an-image-with-ejs-in-node-js-express


I'm just trying to get setup with node.js/express/ejs. I know ejs isn't actual HTML and so I'm having a hard time just displaying a simple image. Can someone point me in the right direction?

Directory structure is:

  • myApp/server.js
  • myApp/views/index.ejs
  • myApp/logo.jpg

Right now I have

// index.ejs
<img src = "../logo.jpg" /> 

Am I going about this the wrong way? Thanks.


+++++++++++++++++++++++++ Answer

Static files in Express must go inside the directory specified in your static middleware. This is commonly ./public/.

For example, in your server.js you may have something like this:

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

Each file inside this folder will be accessible from the root URL, so this will work:

<img src="logo.jpg" /> 


阅读(1012) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~