0

file:///D:/Projects/practice/Node/server.js:129 app.use(express.static(path.join(__dirname, 'public')));
^

ReferenceError: path is not defined

i am using imports for express & body parser & this error keeps showing up. when i change "type":"module" form json file & use require instead of imports,it works fine. can u please help me in importing path. i tried importing path in different ways but then it shows __dirname isnot defined. Can u please help me in importing path.

0

1 Answer 1

1

__dirname is not available when you're using module as type.

You might look at the answer of this question for alternative solutions. Or you can even try -

app.use(express.static('public'));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.