Ask coding questions

← Back to all posts
__dirname repl.it not working
h
RossJames (271)

Hi,

I have a problem on line 6 of my code where __dirname is not defined. It is probably obvious but I have little js experience.

thanks!

Answered by eankeen (1206) [earned 5 cycles]
View Answer
Commentshotnewtop
eankeen (1206)

Not sure if you're still having the issue or @TheDrone7 helped you out, but I would recommend replacing line 6 (or anything that deals with paths) with

res.sendFile(path.join(process.cwd(), "home.html"));

Should work just fine :)

TheDrone7 (989)

There are no issues with your code, it's a minor repl.it bug, a quick workaround would be to declare a new constant named dirname set it's value to '/home/runner' and use dirname instead of __dirname.

RossJames (271)

@TheDrone7 Hi, I have changed my code and still have an error. Any Ideas? thanks.

TheDrone7 (989)

@RossJames it's because you're trying to respond with a folder instead of a file on line number 6

RossJames (271)

@TheDrone7 Even if i change it to a file, i get the error. any ideas?

TheDrone7 (989)

@RossJames it is because of the way you've defined your dirname variable - const dirname = '/home/runner'; is the way to go instead of const dirname = ('/home/runner');

abc3354 (209)

Hi !
This was answered on replit bugs !
If this solution doesn't work, try this one


Replit helper here !
If you found my answer helpful, you can upvote it :)