Exavier
Exavier

Reputation: 93

How to locate a parent folder?

How am I supposed to go back up 1 level to find a file?

I was trying code bellow but It's not working

app.get('/', (req, res) => {
  res.sendFile(__dirname + '../client-side/public/index.html');
});

This is my folder structure

enter image description here

Trying to go public folder under client-side folder

Upvotes: 0

Views: 128

Answers (1)

Dharmaraj
Dharmaraj

Reputation: 50850

You are using + which essentially outputs this path:

'/[__dirname]../client-side/public/index.html'

Try using path module:

const path = require("path")

app.get('/', (req, res) => {
  res.sendFile(path.join(__dirname, '../client-side/public/index.html'));
});

You can read more about path.join() in the documentation

Upvotes: 1

Related Questions