Describe the differences between a SQL and NoSQL database, and when you might use each.
NoSQL: non-relational database
-uses documents and collections instead of rows and tables
-makes it easier to handle and send data between client and database
-faster, more flexible
-automatic scaling
SQL: relational database
-make queries to get data thats connected through a relation
-explicit relationships
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?
if youre finding just one instance then you need to use .findOne; you would console.log(author) instead of results
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"}, (err, instructor)=>{
console.log(instructor)
})
Instructor.create({name: "Andy", description: "Resin Laying Deer Figurine, Gold"}, (err, instructor)=>{
instructor.save((err, instructor)=>{
if(err){
console.log(err)
}
else {
console.log(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")
}
})
class Author < ActiveRecord
def change
create_table :authors do |t|
t.string :name
end
end
end
Author.destroy_all
Author.create!(name: "")
What is module.exports and why do we use it?
it is a reference to the current module/object and exporting it to another file when you do "require"
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();
app.get('/', (req, res) =>{
res.send("hello world")
})
app.post('/', (req, res)=>{
Model.create(req.body.model).then((model)=>{
res.send("post created")
})
})
app.post("/:name", (req, res)=>{
Model.findOneAndUpdate({name: req.params.name}, req.body.model, {new:true}).then((model)=>{
res.send("updated")
})
})
app.post("/:name/delete", (req, res)=>{
Model.findOneAndRemove({name: req.params.name}).then(()=>{
res.send("deleted")
})
}
Describe the differences between Express and Rails as backend frameworks.
-Express:NodeJS::Sinatra:Ruby
-Express is not as strict as Rails and much lighter weight, and faster
What do the following lines of code do?
var bodyParser = require("body-parser")
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended: true}))
body parse is used in order to read POST data HTTP requests in express; it is middleware that reads a input from a form and stores it as an object which is access by req.body
Take a look at these front end developer interview questions