question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to use .env files?

See original GitHub issue

I have a project with a .env file in the root and I use import "dotenv/config"; to load the .env to process.env. I didn’t realize it at first but this is not working with email/index.ts as the env values I’d expect to be defined (present in my .env) are not set on process.env.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
bruceharrison1984commented, Aug 8, 2022

Just wanted to add this is a great feature to build in. I had to slightly tweak mine because I use a file with a different name:

import * as dotenv from 'dotenv';
import { buildSendMail } from 'mailing-core';
import nodemailer from 'nodemailer';

dotenv.config({
  path: '.env.local',
  debug: true,
});

Using debug helped me figure out that due to the way I have tsconfig setup, my base path is the root of the repo, and not the location of emails/index.ts. After that, I was up and running with SendGrid in a matter of minutes.

Great job on this, looking forward to see where it goes!

1reaction
cymencommented, Aug 5, 2022

I edited emails/index.ts to change the contents of a console.log and it’s updating without restarting (wasn’t sure if that would be the case) so I’d chalk this up to some kind of odd edge case.

I’ll keep trying to reproduce as I use mailing but I’m fine with closing this out and can reopen if I can get it to happen again. Sorry for what amounts to noise at the moment.

On a side note, really happy to find mailing – thank you for sharing it. I was already using MJML but had a email template compile step and previewing wasn’t as nice as I’d like (and I wasn’t using react-mjml yet as it didn’t fit well in my workflow). But I’m excited to be able to use all of that and have the excellent preview capabilities of mailing!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Here's how you can actually use Node environment variables
.env files allow you to put your environment variables inside a file. You just create a new file called .env in your project...
Read more >
We need to talk about the .env | Platform.sh
.env files are a surrogate environment variable for local development only, but should never be committed to Git. Understand your application!
Read more >
How to Use Environment Variables in a .env file to fill out other ...
env I have several parts of the environment variable that repeat throughout the file. For example, port and ip are the same for...
Read more >
Continue Using .env Files As Usual. - DEV Community ‍ ‍
Doing so, the .env file can only be read by the owner and no one else. You can use this command in a...
Read more >
.env file - IBM
env file lets you customize your individual working environment variables. Because the .env file is hidden, use the ls -a command to list...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found