How to specify environment variables in loopback 4?
Asked Answered
N

2

11

I found documentation for the previous version https://loopback.io/doc/en/lb3/Environment-specific-configuration.html but I can't find a documentation for the version 4

There's something I'm missing or v4 doesn't yet support environment specific configuration?

Nonrecognition answered 17/10, 2018 at 15:54 Comment(2)
Even I couldn't find how to specify configuration in loopback 4. I was trying to configure a common base path for all the APIs.Archoplasm
hey dude, I put my dotenv configuration in index.js (next to the package.json) and it worked !!! If you want similar solution try...Torrie
A
14

After breaking my head looking for documentation - these are the steps I used to handle environment configuration:

  1. Step 1: Install dotenv package

    npm install --s dotenv

  2. Add a .env file to the root of your project (server/.env). Sample format in this file given below:

    SampleKey=testValue

  3. Require this file from the index.js file (I placed this on line 2)

    // Addition of dotenv for access to process.env (environment variables) const dotenv = require('dotenv').config();

  4. You should be able to access keys from your file now as follows:

    console.log(process.env.SampleKey);

Avidin answered 11/4, 2020 at 20:37 Comment(0)
A
4

Loopback 4 doesn't support environment specific configurations yet. Check this post https://mcmap.net/q/1015981/-loopback-4-test-configurations-are-not-picked-up

You can follow this github issue for the same. https://github.com/strongloop/loopback-next/issues/1464

Archoplasm answered 27/11, 2018 at 15:3 Comment(1)
I'm asking in that issue as well (I'm Edo78 on github)Nonrecognition

© 2022 - 2024 — McMap. All rights reserved.