Giter Club home page Giter Club logo

appacademy_dotenvsetup's Introduction

Practice: Environment Variables

In this practice, you will set up and work with environment variables in a Node.js environment.

Set up

cd into the server folder.

npm install the dependencies.

Part 1: Command-line

The index.js file contains a single console.log that will log the value of the NODE_ENV environment variable; however, it currently prints undefined when running:

> node index.js
> undefined

Run index.js again, but this time with the NODE_ENV environment variable set to "production" and declared within the command-line.

Part 2: Using a .env file

The app.js file contains some boilerplate code for an Express server. However, it is dependent on some environment variables. Identify the environment variables that the application is using.

Set the environment variables so that the server:

However, instead of defining the environment variables through the command-line, use a .env file to set the environment variables that the server needs.

Create the .env file with the appropriate environment variables and values. Then, use dotenv to connect your environment variables so that the Express application runs with the configured environment variables.

Important Note: You will need to npm install the appropriate node modules to use dotenv.

What you've learned

You learned one way for setting and loading environment variables in a Node.js application and another way for setting and loading environment variables in an Express application.

appacademy_dotenvsetup's People

Contributors

chriscarucci avatar

Watchers

 avatar

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.