简体   繁体   中英

Import file to node from ENV variable

I am trying to import json file from system, in script if i go with :

const creds = require('C:\\Users\\WTF\\creds.json');

then I can see the imported file, but when I try this with env variable as such:

 $env:LOCAL_ENV_CREDENTIALS="C:\Users\WTF\creds.json" //powershell command to set to env
const creds = require(process.env.env:LOCAL_ENV_CREDENTIALS as string); //fetching code

then I get the error

"message": "Cannot find module 'C:\\Users\\WTF\\creds.json'",

I'd log your process.env in the node script to ensure it can see the variable. Also it looks like the line should be changed to

const creds = require(process.env.LOCAL_ENV_CREDENTIALS); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM