You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to load an image from another directory located outside the workspace.
In app.js, I have used:
var staticResource='C:\Users\Sachin\Desktop\profile\img';
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(staticResource, 'public2')));
And in pug:
img(src='/public2/one.jpg')
When I run my application, it displays
Failed to load resource: the server responded with a status of 404 (Not Found)
It is looking in
localhost:3000/public2/one.jpg for image.
Can anyone help me?
Thanks in advance
The text was updated successfully, but these errors were encountered:
sachinavinaw
changed the title
How to access image form directory located outside the workspace?
How to access image fromm directory located outside the workspace?
Jul 20, 2017
sachinavinaw
changed the title
How to access image fromm directory located outside the workspace?
How to access image from directory located outside the workspace?
Jul 20, 2017
This is more of an expressjs issue than krakenjs (which builds on top of it), but an important thing to note with express.static is this:
Express looks up the files relative to the static directory, so the name of the static directory is not part of the URL.
So, if you wanted that behavior you should call app.use() passing in the route prefix as the first argument:
// omit the first arg to app.use if you do not want the /public prefix for these assetsapp.use('/public',express.static(path.join(__dirname,'public')));varstaticResource='C:/Users/Sachin/Desktop/profile/img';app.use('/public2',express.static(path.join(staticResource,'public2')));
I am new to express Js.
My application structure is as following
I want to load an image from another directory located outside the workspace.
In app.js, I have used:
And in pug:
img(src='/public2/one.jpg')
When I run my application, it displays
It is looking in
localhost:3000/public2/one.jpg
for image.Can anyone help me?
Thanks in advance
The text was updated successfully, but these errors were encountered: