PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, August 21, 2022

[FIXED] How can I use template literals in an .env file?

 August 21, 2022     environment-variables, javascript, jwt     No comments   

Issue

I want to use JavaScript's Template Literals in an .env file.

Specifically, I am trying to store a JWT public key in the .env file:

PUBLIC_KEY=
`--BEGIN PUBLIC--
AAAAAA
BBBBBB
CCCCCC
--END PUBLIC--`

But when I try to pull it out using process.env.PUBLIC_KEY JS returns an empty string.

I am using gulp to translate TypeScript but the .env is in the root directory and is required at the start of the gulpfile.


Solution

Good news. v16.0.0 and greater now supports JavaScript Template Literals.

You can use it like the following:

PUBLIC_KEY=`--BEGIN PUBLIC--
AAAAAA
BBBBBB
CCCCCC
--END PUBLIC--`


Answered By - Mot
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,204,664

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing