GithubHelp home page GithubHelp logo

cse341-l2's Introduction

Lesson 02 Class Activity Starting Code

This code begins where we left off with the lesson 01 personal assignment.

The purpose of this activity is to give students experience working with MongoDB because they will need to know how to do this for their personal assignments

Steps to Complete

  • The starter code is a sample solution of the lesson 1 assignment
  • Run npm install to install dependencies listed in package.json
  • Run npm start to start the application. Keep the terminal open so you can see errors as you go through the following steps
  • Navigate to Mongodb.com and create a new database if you don't have one
  • Connect using MongoDB Compass, ensure it is installed, and you can connect using your username and password
  • Create a collection called user and add one user that has a single field called username and a value.
  • Create a folder in the root of your project called db
  • Create a file in db/ called connect.js that follows the implementation of the mongodb.js file posted by SuleymanSah
  • We don't want to store sensitive database information in a JavaScript file directly
  • You will move your sensitive db info to an environment variable file which will not go to GitHub or ever be published. You can get help setting this up with this article
  • Modify server.js to only listen() if mongodb connected successfully
  • Create a route that will retrieve your user from the db
  • Notice that the logic involved to create this mongodb request causes your route to become cluttered. Create a controllers folder with a file called user.js
  • Create a function in the controller that will retrieve the user and return it as json when the route is requested
  • Test the route using Rest Client
  • Once this is working, create another route, and another controller function to only return the username of the user

Solution

GitHub Repo

cse341-l2's People

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.