0

I keep seeing this error:

Error: Cannot find module 'E:\LARRY\FDC\stesh\backend\routes/core/util' What i don`t understand is the the forward slash and back slash.

my code looks like this.

const appRoot = __dirname + '/../../'; var util = require(__dirname + '/../../core/util');

what could be the solution to the forward slash backward menace?

Miami Larry
  • 29
  • 10

2 Answers2

0

You could use the .replace function to swap all the path separators in the string.

const appRoot = (__dirname + '/../../').replace("\\","/");
Abel
  • 111
  • 4
0

Backslashes are the platform specific delimiter for file paths on Windows, which is why __dirnamewill yield E:\LARRY\FDC\stesh\backend\routes in your case.

Note that when dealing with paths, you should always use the path module which will ensure cross-platform functionality for all the paths you want to access.

Also you should not pass a direct path to require but a relative path instead (see Node require absolute path for more details).

eol
  • 23,236
  • 5
  • 46
  • 64