Expand my Community achievements bar.

how to read a json file in the aio app builder js

Avatar

Level 4

Hi,

 

I am working on some requirements in aem with aio app builder. so i am trying to do the server based token authentication to aem in the app builder code. So when i try to give the json file path, i am getting no "Token file does not exist in the location", why? also, when i try to print the current directory path i am getting this  Current Directory: /nodejsAction/lp25kf3X. So i want to know how to read a json file from the js.. How to give the json file path in index.js?

https://experienceleague.adobe.com/en/docs/experience-manager-learn/getting-started-with-aem-headles....

 

 

One difference here is, instead of getting the filename from command line, i am passing directly in the code or from the AEM MCP to app builder request call.

 

Please let me know if anyone knows the answer! Thanks in advance

 

 

 

Regards,

Bhavani Bharanidharan

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Reply

Avatar

Community Advisor

Hi @BhavaniBharani ,

 

The error "Token file does not exist" likely occurs because the JSON file path is incorrect. Since your current directory is /nodejsAction/lp25kf3X, ensure the JSON file path is correct relative to this directory.

Solution:

  1. Try using path.join(__dirname, 'your-token-file.json') to construct the correct path to your JSON file, where __dirname refers to the directory where your index.js file is running.
  2. Make sure the JSON file is correctly placed and accessible relative to your app’s current directory.

Hope this helps!

 

Thanks

Ritesh Mittal