简体   繁体   中英

How do I list images from folder in node.js

i was trying for list the files what are in that folder with using node express pug module, but got an aerror ie like

Error: ENOENT: no such file or directory, stat '/home/jarvis/Desktop/visageSDK-HTML5/doc/static/public/uploads/0' at Object.statSync (node:fs:1536:3)


at getImagesFromDir (/home/jarvis/Desktop/visageSDK-HTML5/doc/index.js:22:21)
at /home/jarvis/Desktop/visageSDK-HTML5/doc/index.js:14:16
at Layer.handle [as handle_request] (/home/jarvis/Desktop/visageSDK-HTML5/node_modules/express/lib/router/layer.js:95:5)
at next (/home/jarvis/Desktop/visageSDK-HTML5/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/home/jarvis/Desktop/visageSDK-HTML5/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/home/jarvis/Desktop/visageSDK-HTML5/node_modules/express/lib/router/layer.js:95:5)
at /home/jarvis/Desktop/visageSDK-HTML5/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/home/jarvis/Desktop/visageSDK-HTML5/node_modules/express/lib/router/index.js:335:12)
at next (/home/jarvis/Desktop/visageSDK-HTML5/node_modules/express/lib/router/index.js:275:10)

please suggest me the better way, if anybody knows....

The following code is an example of how to get an image or other static files from the node server.

const express = require('express'); 
const app = express();
const PORT = 3000;                 

app.use(express.static('public')); 
app.use('/images', express.static('images'));
 
app.listen(PORT, () => {
  console.log(`Running server on PORT ${PORT}...`);
})

Hope, this answers your question

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM