0
votes

Using app.use(express.static('public')) serves the files located under public folder

But if my files are outside the public folder in my application root directly how to serve them.

2

2 Answers

1
votes

If you want to serve files in a folder outside of the current working directory, './../<dir_name>' is the way to go.

If you want to serve individual files instead of a directory, then you can use either,

app.use("/<some_url>", express.static(__dirname + '<path_to_file>')); 

or

res.sendFile('<path_to_file>');

or use a simple library like, https://www.npmjs.com/package/connect-static-file.

I recommend the first approach though.

Note: replace the <text> with your file names and path names as required.

0
votes

You can use ./../ to go the parent of the current folder. If you have the following structure:

project
-   public
-   app_folder
--     app.js

You can use './../public' as the static folder.