user11054683
user11054683

Reputation:

How can I find the file inside the directory in Node.js?

I am trying server-side js injection for my assignment. I am able to find the directory names using the command:

res.end(require('fs').readdirSync('.').toString())

output:

photos,practice.db,public,routes,fun,server.js,views

Now I want to look inside the 'fun' directory and read it's file content. I tried:

res.end(require(‘fs’).readFileSync(‘fun’))

but it's not working because it's a directory.

Upvotes: 1

Views: 448

Answers (1)

Mehdi
Mehdi

Reputation: 7403

How about this?

res.end(require('fs').readdirSync('./fun').toString())

The code you're trying is using readFileSync instead of readdirSync.

Upvotes: 1

Related Questions