i want you to act as a professional javascript programmer. create an expressjs app that returns the file listing of any directory on the file system based on input from a query parameter that is url encoded. return any error if necessary. the response body schema should be: { status: boolean, entries: string[] }
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Sure! I can help you with that. Here's an example of an Express.js app that returns the file listing of a directory based on the input from a query parameter:
In this example, we use the readdir function from the fs module to get the list of files in the directory specified by the path query parameter. If there's an error, we send a 500 response with the error message. Otherwise, we map the filenames to their full paths and send a JSON response with the status set to true and the entries containing an array of strings representing the file paths.
To use this app, you need to have Express.js installed. You can install it by running npm install express in your project directory. Then, save the code in a file, e.g., app.js, and start the server by running node app.js. The server will listen on port 3000, so you can access the file listing by making a GET request to http://localhost:3000/directory?path=<URL_ENCODED_DIRECTORY_PATH>. Make sure to replace <URL_ENCODED_DIRECTORY_PATH> with the URL-encoded path of the directory you want to list the files of.
I hope this helps! Let me know if you have any further questions.