Linked Questions
12 questions linked to/from Why is __dirname not defined in node REPL?
159
votes
4
answers
124k
views
__dirname is not defined error in Node.js 14 version [duplicate]
I have been using Node.js version 12.3.4, and updated it to 14.14.0 and started to receive a lot of issues which I fixed. The only thing that I don't understand is the issue
__dirname is not defined
...
1190
votes
25
answers
990k
views
How to create a directory if it doesn't exist using Node.js
Is the following the right way to create a directory if it doesn't exist?
It should have full permission for the script and readable by others.
var dir = __dirname + '/upload';
if (!path.existsSync(...
390
votes
26
answers
210k
views
Alternative for __dirname in Node.js when using ES6 modules
I use the flag --experimental-modules when running my Node application in order to use ES6 modules.
However when I use this flag the metavariable __dirname is not available. Is there an alternative ...
161
votes
6
answers
145k
views
Determine command line working directory when running node bin script
I am creating a node command line interface. It is installed globally and uses a bin file to execute.
I plan to have a command window open at the root directory of the files I am working on and then ...
27
votes
3
answers
21k
views
eslint complains about __dirname not being defined in a NodeJS file
I've just started using eslint. I initialized it and started fixing problems it pointed out.
One problem, however, it shouldn't complain about:
const data = fs.readFileSync(path.join(__dirname, ...
4
votes
2
answers
16k
views
__dirname is not defined
I don't understand why my Google Cloud Run instance doesn't know what __dirname is
I have an expressjs server that has this in it:
import path from 'path';
const App = express()
.get('/*', (_req, ...
8
votes
1
answer
4k
views
How to use NodeJS global module objects in RequireJS modules
I decided to use RequireJS as my module loader in NodeJS.
Unfortunately, the modules I define don't have access to some of the "global" objects that would be be available if the modules were loaded ...
9
votes
3
answers
828
views
Getting error "Path" argument must be string while deploying React - Loadable components sample code in cloud functions
I'm trying to integrate Loadable components in my SSR project and that is working when I executed in localhost:3000, then I tried to deploy it in cloud function I am getting this error
[...
0
votes
2
answers
796
views
Why are __filename and __dirname not available in ES modules?
I'm aware that, when using ES modules, __filename and __dirname don't exist.
This is clearly stated in Node.js documentation, and also alternatives can be found in several places, like this answer.
...
1
vote
1
answer
219
views
Using the Node REPL to log the value of __dirname
If I write a script like containing console.log(__dirname); logs the value of __dirname. But if I try the same for the Node REPL like this happens:
> console.log(__dirname)
ReferenceError: ...
1
vote
1
answer
152
views
What is [eval] in context of __filename?
I wanted to see what filename would be returned when I pass the argument __filename to the node binary. In result I was expecting to see the node binary's path which would be evaluating the command ...
2
votes
1
answer
57
views
Force npm test to make fresh\new copy of input
test/
├── TestOne.js
└── TestTwo.js
Say, TestOne.js is :
This test case reads from file InputOne.json and add one record to the object which already has 3 records.
describe('Add Items', function ()...