-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stuck on API creation #47
Comments
Having this exact issue did you ever manage to fix it? |
@mikevarela @peweet Do you guys get any error messages? If so, what are they? |
Here's the error I'm getting. Guessing this is what they're getting as well...
|
I forget if I managed to fix but this is what I think I did. If you read the error carefully it tells you exactly whats wrong. So quite simply the validation has failed because the computer is too stupid to figure out what to do when it has nothing to work with! :-) We need to pass in a generic password and user to fill the undefined value. Or write a usecase to handle the null value. ie a bit of psuedo
So find a way to pass user and password values through the command line to see it works at runtime. If that doesn't work manually try put in values directly into the Javascript.
|
Fisrt, bought and downloaded PDF (Oct 8th 2016)
The newer versions of mongoose caused a break in code.
However,
I'm stuck now trying to figure out why I can't post a user (create) or get someone. I've decided to use MLAB and I've created a database called 'meanmachinebook'
I know that you created a database with an odd name in the book, and you don't elude to creating any collections, like User, user or users.... so not sure how to post or get from this MLAB database.
From my server.js
`// BASE SETUP
// ======================================
// CALL THE PACKAGES --------------------
var express = require('express'); // call express
var app = express(); // define our app using express
var bodyParser = require('body-parser'); // get body-parser
var morgan = require('morgan'); // used to see requests
var mongoose = require('mongoose');
var User = require('./app/models/user');
var port = process.env.PORT || 8080; // set the port for our app
// APP CONFIGURATION ---------------------
// use body parser so we can grab information from POST requests
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// configure our app to handle CORS requests
app.use(function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type, Authorization');
next();
});
// log all requests to the console
app.use(morgan('dev'));
// connect to our database (hosted on MLab)
mongoose.connect('mongodb://xxxxxx:xxxxxxx@ds053196.mlab.com:53196/meanmachinebook');
// ROUTES FOR OUR API
// ======================================
// basic route for the home page
app.get('/', function(req, res) {
res.send('Welcome to the home page!');
});
// get an instance of the express router
var apiRouter = express.Router();
// middleware to use for all requests
apiRouter.use(function(req, res, next) {
// do logging
console.log('Somebody just came to our app!');
});
// test route to make sure everything is working
// accessed at GET http://localhost:8080/api
apiRouter.get('/', function(req, res) {
res.json({ message: 'hooray! welcome to our api!' });
});
// on routes that end in /users
// ----------------------------------------------------
apiRouter.route('/users')
// on routes that end in /users/:user_id
// ----------------------------------------------------
apiRouter.route('/users/:user_id')
// REGISTER OUR ROUTES -------------------------------
app.use('/api', apiRouter);
// START THE SERVER
// =============================================================================
app.listen(port);
console.log('Magic happens on port ' + port);`
The text was updated successfully, but these errors were encountered: