Mongoose and express

Beschreibung

A-Level Node / Express / Mongo Notiz am Mongoose and express, erstellt von James Drummond am 20/04/2015.
James Drummond
Notiz von James Drummond, aktualisiert more than 1 year ago
James Drummond
Erstellt von James Drummond vor mehr als 9 Jahre
16
0

Zusammenfassung der Ressource

Seite 1

Notes from MEAN stack documentQuick Mongo commands: - mongo - starts mongo shell- db - names current database- show databases - list databases // save one user $ db.users.save({ name: 'Chris' }); // save multiple users $ db.users.save([{ name: 'Chris'}, { name: 'Holly' }]); // save one user $ db.users.save({ name: 'Chris' }); // save multiple users $ db.users.save([{ name: 'Chris'}, { name: 'Holly' }]); // remove all db.users.remove({}); // remove one db.users.remove({ name: 'Holly' }); Use Robomongo for GUI interface

Use Mongoose in node: // grab the packages we need var mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/db_name'); package.json { "name": "node-api", "main": "server.js", "dependencies": { "morgan": "~1.5.0", // Loggin "express": "~4.10.3", "body-parser": "~1.9.3", // pull post content from http requests "mongoose": "~3.8.19", "bcrypt-nodejs": "0.0.3" // Hash passwords } }

app.use() See http://expressjs.com/api.html#app.useMounts the middleware function(s) at the path. If path is not specified, it defaults to “/”. Middleware is a bunch of functions that occur in order on the request. Middleware can: Execute any code. Make changes to the request and the response objects. End the request-response cycle. Call the next middleware in the stack. There are several levels of middleware: Application-level middleware - Bound to an instance of the Express application // use body parser so we can grab information from POST requests app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); Router-level middleware - Error-handling middleware Built-in middleware Third-party middleware

Zusammenfassung anzeigen Zusammenfassung ausblenden

ähnlicher Inhalt

Javascript basics
James Drummond
ICT Systems & Components
Calum_Weeks
Chapter 3
michael-cutting
Unit 2 Flashcards
sophiegreer3
Types and Components of Computer Systems
Jess Peason
Using GoConqr to teach French
Sarah Egan
Using GoConqr to teach science
Sarah Egan
Using GoConqr to study geography
Sarah Egan
Using GoConqr to study Economics
Sarah Egan
Using GoConqr to study English literature
Sarah Egan
Using GoConqr to learn French
Sarah Egan