kunalkapadia / express-mongoose-es6-rest-api

:collision: A boilerplate application for building RESTful APIs Microservice in Node.js using express and mongoose in ES6 with code coverage and JsonWebToken Authentication
http://kunalkapadia.github.io/express-mongoose-es6-rest-api/
MIT License
2.95k stars 694 forks source link

How to server static files? #467

Open thunderwin opened 4 years ago

thunderwin commented 4 years ago

app.use("/static", express.static(path.join(__dirname, "public")));

How to server static files?

I did some wrong?

I put it on config/express.js

DangelZM commented 4 years ago

@thunderwin can you share where 'public' folder located in your project structure? app.use('/static', express.static(path.join(dirname, 'public'))) try to find 'public' in config/public if your 'public' folder located in root folder of your project use app.use('/static', express.static(path.join(dirname, '/../public')));

dirname - The directory name of the current module, so it path to directory where located file you add dirname The path.join() method joins all given path segments together using the platform-specific separator as a delimiter, then normalizes the resulting path.