Pkg: Is there a way to use dotenv with pkg?

Created on 22 Feb 2019  路  4Comments  路  Source: vercel/pkg

I'm trying to use pkg with dotenv. I specified .env files as assets for pkg, but when I start the binary file, it throws the well known error about absolute paths.

Which is the recommended way to handle env variables in a very clean way like dotenv without breaking the binary file?

thank you.

Most helpful comment

This was my solution:

const dotenvAbsolutePath = path.join(__dirname, '../.mydotenvname');

  const dotenv = require('dotenv').config({
    path: dotenvAbsolutePath
  });
  if (dotenv.error) {
    throw dotenv.error;
  }

All 4 comments

Fixed passing the full absolute path to dotenv, instead of the file name

Hello,
I tried to put /snapshot/crawl/.env but it's not work.
is my path correct?

Can you please post the solution?

This was my solution:

const dotenvAbsolutePath = path.join(__dirname, '../.mydotenvname');

  const dotenv = require('dotenv').config({
    path: dotenvAbsolutePath
  });
  if (dotenv.error) {
    throw dotenv.error;
  }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Nisthar picture Nisthar  路  4Comments

jflayhart picture jflayhart  路  4Comments

ByeongYeon picture ByeongYeon  路  4Comments

Admiral-Enigma picture Admiral-Enigma  路  3Comments

j-brown picture j-brown  路  4Comments