According to Wikipedia, An environment variable is a dynamic-named value that can affect the way running processes will behave on a computer. They are part of the environment in which a process runs. For example, a running process can query the value of the TEMP environment variable to discover a suitable location to store temporary files, or the HOME or USERPROFILE variable to find the directory structure owned by the user running the process.
In a Node.js project, or any backend API application, environment variables are used to store sensitive data such as API keys, MongoDB usernames or passwords, database connection strings, etc.
Most of the class examples have just a single environment variable that is MONGODB_URI. This variable will have the full connection string to connect to the database.
Create the ".env" file in the root of your project (where your package.json file is)
Add the variable MONGODB_URI to it in this format: MONGODB_URI=mongodb+srv://yourDbUsername:yourDbPassword@cluster0.z2fyj.mongodb.net/yourDatabaseName
Install the dotenv node package for your project. This should be saved in your list of dependencies. You can do this by running the following command in your terminal: npm i --save dotenv
Anywhere in your node application where you want to use an environment variable, you will need these two lines of code first: const dotenv = require('dotenv'); dotenv.config();
You can then use an environment variable like this: process.env.MONGODB_URI
You will also need to set this up on the deployment server, which is Render.com. In your project settings, click Environment, then add the environment variable there as well so that your deployed application can access the Mongo connection string.
From the MongoDB documentation we read:
MongoDB Atlas Cluster is a NoSQL Database-as-a-Service offering in the public cloud (available in Microsoft Azure, Google Cloud Platform, Amazon Web Services). This is a managed MongoDB service, and with just a few clicks, you can set up a working MongoDB cluster, accessible from your favorite web browser.
You don’t need to install any software on your workstation as you can connect to MongoDB directly from the web user interface as well as inspect, query, and visualize data.
You will only need to create one cluster for this class, and likely for many personal projects as well because each cluster can have many databases. Login to mongodb.com and if you have a cluster, you will see it with some metrics on your dashboard. If you do not have one created already, you will click on the button to create a cluster from your mongodb dashboard.
When you create a cluster, you can leave all of the pre-selected values and not change them. Just click "+ Create" then go to the bottom and hit "Create Cluster".
There are generally three primary issues:
The network you are connected to is blocking MongoDB. "BYUI" is one of these networks. BYU-Visitor works great.
The database user and/or password are incorrect. Double check that you have the correct username and password.
The MongoDB network settings are blocking your IP address, or Render.com IP addresses. This is a common problem. You can whitelist your IP address in the MongoDB network settings.
When you create a MongoDB account, it will create an organization for you, as well as a project. These are means of managing a lot of different applications and we won't worry about those in this class.
You will, however, need to create a Cluster. A cluster will be a group of databases. For each project in this class, you only need one database. So if you don't have one, create a cluster, then click Browse. Then you can create a database within the cluster.
Each node.js project for this class will connect to a single database, and the database name will be included at the end of the MONGODB_URI connection string.
A collection is a grouping of documents. If you are familiar with relational databases (RDBMS) a collection is like a table. Both are generally used to hold documents or records of like data...like people, students, classes, cars, recipes, etc.
A document is a single record of data stored in a MongoDB collection. If I have a recipe application, I will have many recipes stored, and many users stored. Each user will be a document in the users collection. Each recipe will be a document in the recipes collection. MongoDB documents are in json format.
As a sign of professionalism and respect, you should complete your work on time. Extenuating circumstances should be discussed with the instructor prior to the assignment's due date.
You will never receive full credit for submitting late work unless you've cleared it with the instructor prior to the assignment due date.
Assignments submitted late will receive a 20% grade deduction per day starting with the minute that they're late. If you are concerned about this deadline, you are always welcome to submit your work early.
In short, push your Node.js project to GitHub. Create a render.com account and connect that to your GitHub account. Create a new Web Service form the render dashboard, and connect it to your node.js project repository. You can name the web service anything you want.
The build command can be set to "npm install".
The start command will be the node command to run your project with your main server file for example: "node server.js" or "node app.js".
Set the app to "Auto-deploy" to Yes
If you have environment variables set up for your local application to run, then you will need to click on "Environment" and add those environment variables there.
From codecademy we read: REST, or REpresentational State Transfer, is an architectural style for providing standards between computer systems on the web, making it easier for systems to communicate with each other. REST-compliant systems, often called RESTful systems, are characterized by how they are stateless and separate the concerns of client and server.
In this class, we build several RESTful APIs. API is an Application Program Interface that will allow different systems to communicate. The APIs we write will be accessible to frontend applications of any type and will provide data from a database. In WDD 230 you called several APIs from the frontend as part of your assignments. In this class, you learn how to create your own APIs using REST protocol which will allow for requests to be made, and json data to be sent back.
Please see the week 2 personal assignment solution code. You will see that the application will not even start listening on a port until the database connection has successfully been made.
Each node project should be in it's own folder and connected to it's own repository. You may have a CSE 341 folder for the class, then store each of your projects in that folder. Each of those projects will be connected to their own git repository.
For file structure within a project, please reference the class examples and assignment solutions to see how to effectively organize each project.
There are many ways to do this. In this class, you will learn about OAuth, which is a great way to manage authentication in your application.
The OAuth provider that we will use is Auth0. You can learn more about it here: https://auth0.com/
For further information on how to set it up to work with your existing API, or how to use it, please see the following FAQ questions.
All instructions here will assume you are using "http://localhost:8080" for your local development.
Application Login URI can be left empty.
Allowed Callback URLs: http://localhost:8080/callback
Allowed Logout URLs: http://localhost:8080
When you start publishing to Render, you will also add your Render URL to the Allowed Callback URLs and Allowed Logout URLs. For example, if your Render URL is "https://my-app.render.com", then you will add "https://my-app.render.com/callback" and "https://my-app.render.com" to the Allowed Callback URLs and Allowed Logout URLs respectively.
Set up the application in Auth0. Follow the Quick Start steps after creating your Auth0 Application to set up your project to support login/logout with Auth0.
Each of the following paragraphs has an idea for a project. You are free to use these and modify them in any way you wish, and are also free to select one of your own. You should create an API about something that interests you. Each of these could also incorporate a User collection that would allow a user to login, and see any data relevant to their account. It is important to note that these may not meet the requirements for a given project for the class, they are simply intended to give you some ideas. Please review the project rubrics as you plan your project (https://cse341.netlify.app/projects).
Weather API: Collection 1: Weather conditions (temperature, humidity, wind speed, etc.). Collection 2: Cities (name, state, county, country, longitude, latitude, elevation, etc.)
News API: Collection 1: News articles (title, content, date, source, etc.). Collection 2: Categories (business, sports, entertainment, etc.)
Currency Exchange API: Collection 1: Currency exchange rates (base currency, target currency, exchange rate, date, etc.). Collection 2: Supported currencies
Movie API: Collection 1: Movies (title, director, release date, genre, etc.). Collection 2: Actors (name, birthdate, nationality, etc.)
Book API: Collection 1: Books (title, author, publication date, genre, etc.). Collection 2: Publishers (name, location, founded, etc.)
Music API: Collection 1: Albums (title, artist, release date, genre, etc.). Collection 2: Songs (title, artist, length, lyrics, etc.)
Recipe API: Collection 1: Recipes (title, ingredients, instructions, cuisine, etc.). Collection 2: Chefs (name, nationality, specialty, etc.)
Fitness API: Collection 1: Workouts (name, description, equipment, etc.). Collection 2: Exercises (name, description, muscles targeted, etc.)
Transportation API: Collection 1: Vehicles (make, model, year, fuel type, etc.). Collection 2: Routes (origin, destination, distance, estimated time, etc.)
Geolocation API: Collection 1: Locations (latitude, longitude, address, etc.). Collection 2: Landmarks (name, description, location, etc.)
Real Estate API: Collection 1: Properties (address, square footage, price, etc.). Collection 2: Agents (name, company, specialties, etc.)
Job API: Collection 1: Job postings (title, company, location, description, etc.). Collection 2: Applicants (name, resume, cover letter, etc.)
Event API: Collection 1: Events (title, location, date, time, etc.). Collection 2: Attendees (name, email, phone number, etc.)
Sports API: Collection 1: Teams (name, location, sport, etc.). Collection 2: Players (name, position, stats, etc.)
Education API: Collection 1: Courses (title, description, level, etc.). Collection 2: Students (name, email, courses taken, etc.)
Healthcare API: Collection 1: Patients (name, medical history, allergies, etc.). Collection 2: Providers (name, specialty, location, etc.)
Travel API: Collection 1: Destinations (name, location, attractions, etc.). Collection 2: Hotels (name, location, ratings, etc.)
Food API: Collection 1: Restaurants (name, location, cuisine, etc.). Collection 2: Menu (year, food types, beverage types, foods, beverages, prices, etc.)
Shopping API: Collection 1: Products (name, description, price, etc.). Collection 2: Orders (products, total price, customer information, etc.)
Social Media API: Collection 1: Users (username, password, profile information, etc.). Collection 2: Posts (content, date, user, etc.)
E-commerce API: Collection 1: Products (name, description, price, etc.). Collection 2: Shopping carts (products, total price, customer information, etc.)
Government API: Collection 1: Government services (name, description, location, etc.). Collection 2: Citizens (name, address, nationality, etc.)
Climate API: Collection 1: Climate data (temperature, humidity, precipitation, etc.). Collection 2: Locations (latitude, longitude, name, etc.)
Finance API: Collection 1: Stock prices (symbol, price, date, etc.). Collection 2: Portfolios (stocks, total value, user, etc.)
Email API: Collection 1: Emails (sender, recipient, subject, content, etc.). Collection 2: Contacts (name, email, etc.)
Chat API: Collection 1: Conversations (users, messages, etc.). Collection 2: Users (username, password, profile information, etc.)
Gaming API: Collection 1: Games (name, genre, platform, etc.). Collection 2: High scores (game, user, score, etc.)
Image API: Collection 1: Images (URL, description, date, etc.). Collection 2: Albums (title, images, user, etc.)
Video API: Collection 1: Videos (URL, description, date, etc.). Collection 2: Playlists (title, videos, user, etc.)
Calendar API: Collection 1: Events (title, date, time, location, etc.). Collection 2: Calendars (events, owner, etc.)
Time API: Collection 1: Time zones (name, offset, etc.). Collection 2: Clocks (time, location, etc.)
Date API: Collection 1: Holidays (name, date, location, etc.). Collection 2: Dates (day, month, year, etc.)
Vehicle API: Collection 1: Vehicles (make, model, year, fuel type, etc.). Collection 2: Maintenance records (vehicle, date, service performed, etc.)
Logistics API: Collection 1: Shipments (origin, destination, delivery date, etc.). Collection 2: Vehicles (make, model, year, etc.)
Language API: Collection 1: Languages (name, ISO code, etc.). Collection 2: Translations (text, source language, target language, etc.)
Map API: Collection 1: Locations (latitude, longitude, name, etc.). Collection 2: Routes (start location, end location, distance, etc.)
Translation API: Collection 1: Languages (name, ISO code, etc.). Collection 2: Translations (text, source language, target language, etc.)
Music API: Collection 1: Artists (name, genre, etc.). Collection 2: Albums (title, artist, release date, etc.)
Podcast API: Collection 1: Podcasts (title, host, description, etc.). Collection 2: Episodes (title, podcast, release date, etc.)
Health API: Collection 1: Patients (name, age, medical history, etc.). Collection 2: Appointments (patient, doctor, date, time, etc.)
Weather API: Collection 1: Cities (name, country, etc.). Collection 2: Weather data (temperature, humidity, precipitation, etc.)
Job API: Collection 1: Jobs (title, description, salary, etc.). Collection 2: Applications (job, applicant, resume, etc.)
Travel API: Collection 1: Destinations (name, country, etc.). Collection 2: Bookings (destination, date, number of travelers, etc.)
Real Estate API: Collection 1: Properties (address, price, square footage, etc.). Collection 2: Listings (property, agent, date listed, etc.)
Movie API: Collection 1: Movies (title, release date, etc.). Collection 2: Ratings (movie, user, rating, etc.)
News API: Collection 1: Articles (title, author, date, etc.). Collection 2: Sources (name, URL, etc.)
Fitness API: Collection 1: Exercises (name, description, etc.). Collection 2: Workouts (exercises, date, user, etc.)
Payment API: Collection 1: Transactions (amount, date, user, etc.). Collection 2: Users (username, password, payment information, etc.)
Sport API: Collection 1: Teams (name, sport, etc.). Collection 2: Games (teams, date, location, etc.)
Space API: Collection 1: Planets (name, distance from the sun, etc.). Collection 2: Spacecraft (name, mission, etc.)