Giter Club home page Giter Club logo

Comments (12)

bryankennedy avatar bryankennedy commented on July 27, 2024 1

I think I have a similar issue.

I run my serverless code inside of a subfolder of my larger project and the .env.${NODE_ENV} file is at the root. So in my server package I have this script:

NODE_ENV=development serverless deploy

Within my serverless.yml with the dotenv plugin I have:

custom:
  dotenv:
    path: ../../.env.${env:NODE_ENV}

But that doesn't work. The system doesn't load any of the env vars in that file.

If I hard code it like:

custom:
  dotenv:
    path: ../../.env.development

It works fine.

Is it possible to use environment variables in the setup of dotenv before it loads them from the file? I hope that makes a bit of sense. @SarasArya I hope this is the same as what you're trying to accomplish.

from serverless-dotenv-plugin.

colynb avatar colynb commented on July 27, 2024

Hi SarasArya, I'm having trouble wrapping my head around what the issue is. Is there any way you can point me to an example project or record a screencast, or something more visual?

from serverless-dotenv-plugin.

webchaz avatar webchaz commented on July 27, 2024

@bryankennedy Were you able to find a solution to this? I'm in the same boat.

from serverless-dotenv-plugin.

bryankennedy avatar bryankennedy commented on July 27, 2024

Unfortunately, I'm just working around this by having multiple .env files for now. This allows me to just directly reference the .env file without trying to go outside of the containing directory. Not ideal, but it's all that I could get working for now.

from serverless-dotenv-plugin.

colynb avatar colynb commented on July 27, 2024

@bryankennedy I haven't looked at the code in a long time but if you take a look at the source code you see that .env.[NODE_ENV] will get loaded automatically. There's no need to include that in your config. Let me know if I'm missing something.

from serverless-dotenv-plugin.

SarasArya avatar SarasArya commented on July 27, 2024

Hey @bryankennedy My issue was the same. Also, there should be an option on where is my .env file. It assumes it's in my root of the service. But what if it's not. What if it's in the root of the project. Hence the readFrom option

from serverless-dotenv-plugin.

webchaz avatar webchaz commented on July 27, 2024

@colynb It's just this line here: https://github.com/colynb/serverless-dotenv-plugin/blob/master/index.js#L33

Since it's just returning the path, it doesn't support '.production', '.development', etc. It needs the fully resolved path + name. If this was updated to be the same as the next return, only with path prepended should be all good.

from serverless-dotenv-plugin.

colynb avatar colynb commented on July 27, 2024

Since it's just returning the path, it doesn't support '.production', '.development', etc. It needs the fully resolved path + name. If this was updated to be the same as the next return, only with path prepended should be all good.

@webchaz I see. Because the path is custom, you lose the ability to use the environment. If a lot of people are using the path config option to set the full path instead of the base path, I make an update as you suggested, it would be a breaking change I think. I might have to include another option like "basePath".

from serverless-dotenv-plugin.

webchaz avatar webchaz commented on July 27, 2024

@colynb that would be great or maybe a new major version to keep the api the same - totally up to you, either way would be awesome!

from serverless-dotenv-plugin.

webchaz avatar webchaz commented on July 27, 2024

@colynb This should handle it:

resolveEnvFileName(env)  {
  const configPath = (this.config && this.config.path) ? this.config.path : ''
  return fs.existsSync(`${configPath}.env.${env}`) ? configPath + '.env.' + env : '.env'
}

from serverless-dotenv-plugin.

colynb avatar colynb commented on July 27, 2024

Ok, I just published a new version, 2.1.0. It includes a basePath option now.

from serverless-dotenv-plugin.

webchaz avatar webchaz commented on July 27, 2024

@colynb Awesome, just tried it out, works great - thank you!

from serverless-dotenv-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.