0

i was trying for list the files what are in that folder with using node express pug module , but got an aerror i.e 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....

Nandu
  • 1
  • 1
  • Isn't this answers your question https://stackoverflow.com/questions/2727167/how-do-you-get-a-list-of-the-names-of-all-files-present-in-a-directory-in-node-j – David Dec 09 '21 at 13:50
  • 1
    The error message is more then clear. "ENOENT": no such file or directory. – Marc Dec 09 '21 at 14:03

1 Answers1

0

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

Gautam Kothari
  • 301
  • 2
  • 8