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

Saturday, November 5, 2022

[FIXED] How do I add environment variables to a AWS Lightsail Node.js instance?

 November 05, 2022     amazon-lightsail, amazon-web-services, environment-variables, linux, node.js     No comments   

Issue

The Problem

I'm dipping my toes into AWS by deploying a simple API built with NestJS. This will be the first app I've deployed to a cloud service. I've already cloned my repository on an AWS Lightsail Linux instance with Node.js and installed all of my dependencies. However, I'm confused on how best to provide environment variables to my app.

Obviously, I has a local .env file that I used during development with credentials for my database, port info, etc. Do I just create a new .env file on the machine running my instance through the command line? I've read that for other AWS services you can provide env variables through that service's UI, but I can't find the same thing for Lightsail.

I would greatly appreciate it if someone could give me an explanation of env variables, and how we should generally provide them to cloud services.

Thank you!


Solution

There could be a better method. But, you could add a file locally on the LightSail server itself. If you don't know how to do so through console, I'll explain below.

  1. Create the file: touch .env
  2. Open up the file in console: vim .env. Now you will see the file opened up in console, with weird UI if you haven't seen it before.
  3. Prepare to write to file: press i. Now you should see a the ~Insert~ mode appear at the bottom.
  4. Add the variables: copy and paste your .env from your local laptop to your lightsail console.
  5. close out: press esc, then type in :wq, and click on enter

This should work as normal with any .env file. I'm unsure if there are security issues with this, but I don't believe so.



Answered By - Askar
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • 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,719

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