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.

1 Answers1

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'));
Viral Patel
  • 1,104
  • 4
  • 7