GithubHelp home page GithubHelp logo

checkpoint-07's Introduction

Week 10

Mongoose

Question #1

Describe the differences between a SQL and NoSQL database, and when you might use each.

SQL databases are characterized as relational whereas NoSQL databases are non-relational. SQL is also table based while NoSQL is document based.

Question #2

What's wrong with this Mongoose code and how might we fix it?

var results = AuthorModel.find({name: "Bob"});
console.log(results);

Hint: Assuming there is a document with a name of "Bob", why does results not contain an author model on the second line?

Unless `mongoose.model` was set to a variable called `AuthorModel` this line of code will not work. It would probably be better to do:

var Author = mongoose.model('Author')
var results = Author.find({name: 'Bob'})

Question #3

Convert the Ruby and ActiveRecord code below into Javascript and Mongoose code:

@andy = Instructor.find_by(name: "Andy")
@andy.wishlist_items.create(description: "Resin Laying Deer Figurine, Gold")
Instructor.findOne({name: "Andy"}).then(function(instructor){
    res.json(instructor)
  });

Instructor.create(req.params.wishlist_items).then(function(instructor){
  res.json(instructor)
})

Question #4

Convert the following create method in Mongoose to ActiveRecord.

var author = new Author({name: req.body.name})
author.save(function(err){
  if (!err){
    res.redirect("authors")
  }
})
def new
  Author.new
end

def create
  @author = Author.create(:name)
  redirect_to author_path(@author)
end

Express

Question #5

What is module.exports and why do we use it?

`module.exports` is used in regards to the seperation of concerns; instead of putting all of your code in one file, files are wrapped in `module.exports` in order for their variables to be used within seperate files.

Question #6

Write one Express route for each of the four HTTP methods.

Then, make each route respond with a one-word string containing the RESTful action that would most likely be associated with this route.

var express = require("express");
var app = express();

// Your code starts here...
app.get("/", function(req, res){
  console.log("index")
})

app.post("/new", function(req, res){
  console.log("new")
})

app.put("/edit", function(req, res){
  console.log("update")
})

app.delete("/edit", function(req, res){
  console.log("delete")
})

Question #7

Describe the differences between Express and Rails as backend frameworks.

Well first, Express uses Javascript while Rails uses Ruby. Additionally, Rails is more opinionated than Express is, meaning developers are given more freedom but less structure when using Express as a backend framework. Rails has more strict guidelines.

Question #8

What do the following lines of code do?

var bodyParser = require("body-parser")
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended: true}))
The first line allows us to handle AJAX requests with JSON bodies. It will run a request through JSON before providing a response (I think).

If You Finish Early...

Take a look at these front end developer interview questions

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.