ERROR: NodeJs script getting ENOTDIR when attempting fs.readdirSync - unable to set path to desired location

Not applicable

Running NodeJs script with the following:

var __dirname = '/opt/apigee4/data/apigee/custom_jars/gridjars'; var files = fs.readdirSync(__dirname);

Receiving the following error:

<faultstring>Script node executed prematurely: Error: ENOTDIR:/opt/apigee4/var/log/apigee/message-processor/work/o/Vasu/e/dev/a/TestArchGrid-D1__1/node/opt/apigee4/data/apigee/custom_jars/gridjars

It appears to be prepending the directory location where the API is running to whatever I try to assign as my jar location directory. I've tried relative path names, etc...but no matter what, the API root directory is added.

Thanks in advance for any help!

Solved Solved
0 3 5,732
1 ACCEPTED SOLUTION

@MikeHarris @vb878 pls refer to the answer here, i think they are related

Thanks,

View solution in original post

3 REPLIES 3

__dirname is the default variable that holds the current directory of script execution which is [/opt/apigee4/var/log/apigee/message-processor/work/o/Vasu/e/dev/a/TestArchGrid-D1__1/node] in your case.

probably you need to do relative path,

but what are you trying to do? can you bundle those resources within your proxy under resources/node, so you could reference them as __dirname + 'your resources'.

why are you loading jars?

Thanks

I am faced with the same issue when trying to load jars from my node.js app. Below are the options I have tried and both failed. Option 1 is my preference. Option 1 works using trireme as a standalone but fails when I run in Apigee.

Option 1: I load in a custom directory and set __dirname and yet, the Apigee tries ignores the directory I have set and reads from a different default.

Option 2: When I try fs.readdir instead of fs.readdirSync, and put all jars in resources/node and I don't over ride __dirname so it can point to /organization/environment/api/ and I pace my jars under that directory, I get error:

I have jar.loading.allowed=true set in nodejs.properties.

My preference is Option 1. Can you find the resolution to Option 1.

@MikeHarris @vb878 pls refer to the answer here, i think they are related

Thanks,