//accessToken.mjs
import * as dotenv from "dotenv";
dotenv.config();
import { Web3Storage } from "web3.storage";
function getAccessToken() {
// WEB3STORAGE_TOKEN environment variable before you run your code.
console.log(process.env.WEB3STORAGE_TOKEN);
return process.env.WEB3STORAGE_TOKEN;
}
getAccessToken();
function makeStorageClient() {
return new Web3Storage({ token: getAccessToken() });
}
export default makeStorageClient;
running the command below
$ node .\accessToken.mjs
undefined
I added a .env file in the root directory and didn't use any quote or semicolon. I am still not able to get the WEB3STORAGE_TOKEN value.
Updated:
I don't know how you are working with other files but if you want to use import statements in NodeJs you need to add
typeattribute insidepackage.jsonlike so:and in your code file use import like this
You can see here in demo
Just put this on the top
Instead of