how to read a json file in the aio app builder js | Community
Skip to main content
Level 4
November 5, 2024
Question

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

  • November 5, 2024
  • 2 replies
  • 730 views

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-headless/authentication/overview.

 

 

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

Ritesh_Mittal
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
November 19, 2024

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

kautuk_sahni
Community Manager
Community Manager
November 26, 2024

@bhavanibharani Did you find the suggestion helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!

Kautuk Sahni