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.
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'})
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)
})
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
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.
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")
})
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.
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).
Take a look at these front end developer interview questions