mongoose getting `TypeError: user.save is not a function` - what is wrong : <p>I am trying to post the user data to <code>mongodb</code> but I am getting an error as : </p>

<p>`TypeError: user.save is not a function' - how to fix this?</p>

<p>here is my code :</p>

<pre><code>var

    express     = require('express'),
    app         = express(),
    bodyParser  = require('body-parser'),
    mongoose    = require('mongoose'),
    PORT        = process.env.PORT || 8080;



//connect to db 

mongoose.connect('mongodb://3gwebtrain:admsin@ds147975.mlab.com:47975/family');

app.use( bodyParser.urlencoded({extended : true }));
app.use( bodyParser.json() );


app.get('/', function( req, res ) {

    res.json({message:'works'})

});


var Schema = mongoose.Schema;

var User = new Schema({

    name:String,
    username:{type:String, required:true, index:{unique:true}},
    password:{type:String, required:true, select:false}

})


var apiRouter = express.Router();


apiRouter
    .get('/users', function( req, res ){

        res.send( "yet to get users!");

    })
    .post('/users', function( req, res ) {

        var user = User;

        user.name = req.body.name;
        user.username = req.body.username;
        user.password = req.body.password;

        user.save(function(err) {

            if( err ) {

                console.log( err ); //TypeError: user.save is not a function

            }

            res.send("user created!");

        })

    })


app.use('/api', apiRouter);


app.listen( PORT );
console.log( 'app listens at ' + PORT );
</code></pre>
