Reputation: 181
If I have an nodejs express application with folowing folder structure:
-src
- client
- public
- css
- js
- ...
- views
- server
- server.js
above
the index.js root location?app.use(express.static();
look like?
----UPDATE---
SOLVED this by using: app.use(express.static(path.join(__dirname, '/../client/public')));
Upvotes: 6
Views: 7881
Reputation: 181
Actually solved my problem by using:
app.use(express.static(path.join(__dirname, '/../client/public')));
Upvotes: 9
Reputation: 7991
just do this, (as per your directory structure)
app.use(express.static(path.join(__dirname, 'src/client/public')));
// http://localhost:3000/hello.html
or
app.use('/static', express.static(path.join(__dirname, 'src/client/public')))
// http://localhost:3000/static/hello.html
Upvotes: 1
Reputation: 255
You can use path.join()
app.use(express.static(path.join(__dirname,'public')));
Upvotes: 1