Hi everyone,
First of all, I would like to thank @KenWhitesell for his contribution to resolve the issues I encountered by building webpages. By his advice, hints given to me I have learned what I had no clue for.
Now, I am using Node.js inside Django framework to get data by API call and render these data by Django views.py on a template. I created a .env file to store credentials and wanted to check if the Node.js reads it. E.g.
// .env
API = "here is my api key"
URL = "here is my url"
USERNAME = "here is my username" etc
// node.js file
require('dotenv").config({path: require("find-config")("./.env")}) // when the file in the same folder where .js file invoked
// I tried this one too
const path = require("path")
// require('dotenv").config({path: path.join(__dirname: "./.env") })
// require('dotenv").config({path: path.resolve(__dirname + "./.env") })
// require('dotenv").config({path: path.resolve(__dirname + "full_path_to/.env") })
dct = {
"API_KEY": process.env.API,
"URL" : process.env.URL
}
console.log( dct.API_KEY );
Whatever ways I try to check the API on the terminal, I’m getting output undefined though.
I read articles that for Windows10 users in some cases we have to define .env in settings.json of VSCode to enable it. E.g.
"files.associations" : {
"*.env.*": "env",
".env.*": "properties", // in case you .env file named as *.env.local* etc
".env": "env",
}
"files.include" : {
"env*": true
}
"search.include": {
"**/env": true,
}
Even providing these settings the node.js did not see / read/ find .env file in VSCode. Although with Python it works without any trouble.
Could someone please tell me what reason the Node.js cannot get the values of .env file inside Django for?
The code works on Chromebook perfectly whereever I store .env file to get desired connection with the server, but not in VSCode on Windows 10.
The link for git repo: django-CloudAppDevelopment_Capstone/functions at master · Kanatbek-AKA/django-CloudAppDevelopment_Capstone · GitHub
I appreciate your feedbacks.
Kind regards,
Kanatbek