Q:

How to create simple restful api for login and signup using node.js mongodb express.js

How to create restful api using node.js, express.js and mongo db. I need how to write the schema for login and sign up pages and how to compare the data with mongodb using nodejs express js.
I am beginner to nodejs please help me with some examples.

A:

    //the simple example of login// 

        router.post('/users/login', function (req, res) {
            var users = req.app;
            var email = req.body.email;
            var password = req.body.password;
            if (email.length > 0 && password.length > 0) {
                users.findOne({email: email, password: password}, function (err, user) {
                    if (err) {
                        res.json({status: 0, message: err});
                    }
                    if (!user) {
                        res.json({status: 0, msg: "not found"});
                    }
                    res.json({status: 1, id: user._id, message: " success"});
                })
            } else {
                res.json({status: 0, msg: "Invalid Fields"});
            }
        });

    //and if you have to create schema 

 var db_schema = new Schema({
                email: {type: String, required: true, unique: true},
                password: {type: String, required: true, unique: true},
            });
// define this in your db.js
      var login_db = mongoose.model('your_db_name', db_schema);
        return function (req, res, next) {
                req.app = login_db;
                next();
            }; 

