Section 13: Creating JSON API's with Node and Mongo Flashcards
Define IDE
Integrated development environment.
An integrated development environment is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of at least a source code editor, build automation tools and a debugger.
How do you start writing a node application so that you can keep track of all dependencies?
With the command:
‘npm init’
How do you install express?
npm install –save express
What steps are needed to start the most basic express app?
- Install express
- Require express
express = require(‘express’) - Execute contents of express
app = express() - Start server
app.listen()
How do you stop the server, or Mongod in the terminal?
ctrl + c
How do you define a schema with mongoose?
var newSchema = new mongoose.Schema({ completed: { type: Boolean, default: false });
How do you declare a mongoose model?
var Todo = mongoose.model(‘Todo’, todoSchema);
How do you export things out of a js file while using node.js?
Use:
module.exports = (thing-to-export)
How do you start a MongoDB?
./mongod
In the root directory, and leave it running.
How do you get ‘/api/todos’ in front of all of your routes?
app. use(‘/api/todos’, todoRoutes);
* This will put that prefix in front of all of them.
How do you gain the ability to reference the body?
- Install Body Parser:
npm install –save body-parser - Require it:
bodyParser = require(‘body-parser’); - Use it: (twice)
app. use(bodyParser.json());
app. use(bodyParser.urlencoded({extended: true}));
How do you get things out of the GET request?
router.get(‘/:todoID’, function(req, res){
db.Todo.findById(req.params.todoID);
})
- You pass in the id in as a route variable, and then it’s stored in the ‘params’ object under the id you gave it.
Name the 7 routes
- Index
- New
- Create
- Show
- Edit
- Update
- Destroy
What’s the route, URL and HTTP Verb to display a list of all blogs?
Index
/blogs
GET
What’s the route, URL and HTTP Verb to show a form to make new blogs?
New
/blog/new
GET