Describe the differences between a SQL and NoSQL DB, and when you might use each.
SQL, short for sequel, describes a relational database. It is useful for more complex, schematic data. When more flexibility is required in the construction of each document, a noSQL db is more suited.
What's wrong with this mongoose code and how might we fix it? (Hint: Assuming there is a document with a name of "Bob", why is results not an author model on the second line?)
var results = AuthorModel.find({name: "Bob"});
console.log(results);
var results = AuthorModel.findOne({name: "Bob"});
console.log(results);
Convert the following ActiveRecord sequence to Mongoose:
@andy = Instructor.find_by(name: "Andy")
@andy.wishlist_items.create(description: "Resin Laying Deer Figurine, Gold")
var Andy = Instructor.findOne({name: "Andy"})
Andy.wishlist_items.push({description: "Resin Laying Deer Figurine, Gold"})
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")
}
})
@author = Author.new(name: params[:name])
@author.save
What is module.exports and why do we use it?
module.exports defines the code that is exported to the next document. For example, if we set module.exports to mongoose, that variable alone, including all changes we make to it in the course of our js, will be carried over where it is called. Not well explained, sorry, but I know how to use it. Happy Monday.
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('/', (req, res) => {
res.send("get")
})
app.post('/', (req, res) => {
res.send("post")
})
app.update('/', (req, res) => {
res.send("update")
})
app.delete('/', (req, res) => {
res.send("delete")
})
Describe the differences between Express and Rails as backend frameworks.
First is the language that each is written in. Also, Rails is opinionated and Express is the wild West.
What do the following lines of code do?
var bodyParser = require("body-parser")
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended: true}))
Body-parser allows us to grab the content of forms and use it with req.body. The line containing json sets its return as a json object, and urlencoded({extended: true}) allows us to use the 'querystring' library on it, rather than 'qs' library. This allows for rich objects and arrays, for an end object more similar to json.
Take a look at these front end developer interview questions