Displaying an image with EJS in node.js/express

来源:互联网 发布:windows程序设计第六版 编辑:程序博客网 时间:2024/04/27 22: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" /> 


<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(36) | 评论(0) | 转发(0) |
0

上一篇:Nodejs开发框架Express4.x开发手记

下一篇:HTML5调用手机摄像头拍照 - getUserMedia.js

相关热门文章
  • Android之开发环境搭建
  • Android自定义View的实现...
  • AndroidManifest.xml配置文件...
  • Android相对布局+圆角按钮+Sha...
  • 查看Android应用包名package和...
  • linux dhcp peizhi roc
  • 关于Unix文件的软链接
  • 求教这个命令什么意思,我是新...
  • sed -e "/grep/d" 是什么意思...
  • 谁能够帮我解决LINUX 2.6 10...
给主人留下些什么吧!~~
原创粉丝点击