title: How to fix .save is not a function for mongoose in NodeJs
body: <p>I am writing a small piece of MEAN stack code that adds a post in the mongo data base. I created the schema and when I try to use .save() for my post it is throwing error</p>
  
  <blockquote>
    <p>post.save is not a function</p>
  </blockquote>
  
  <p>Here is my schema</p>
  
  <pre><code>const mongoose =  require('mongoose');
  
  const postSchema = {
      title : {type :String, require : true},
      content : {type : String, default :'No Content'}
  }
  
  module.exports=mongoose.model('Post',postSchema);
  </code></pre>
  
  <p>Here is my app.js</p>
  
  <pre><code>const express = require('express');
  const bodyParser = require('body-parser');
  const mongoose = require('mongoose');
  
  
  const app = express();
  
  
  mongoose.connect('mongodb+srv://venkatmokka:z0L7qSALBehoNPlT@cluster0-vr2p5.mongodb.net/mean-stack?retryWrites=true',{ useNewUrlParser: true })
      .then(()=&gt;{
          console.log('Connected successfully');
      })
      .catch(()=&gt;{
          console.log('Connection failed');
      });
  app.use(bodyParser.json());
  
  app.use((req,res,next)=&gt;{
      res.setHeader('Access-Control-Allow-Origin','*');
      res.setHeader('Access-Control-Allow-Headers','Origin, X-Requested-With, Content-Type, Accept');
      res.setHeader('Access-Control-Allow-Methods','GET,POST,DELETE,OPTIONS');
      next();
  });
  
  app.post('/api/posts',(req,res,next)=&gt;{
      const post = req.body;
      console.log(post);
  
      // Save code that's throwing an error
      post.save();
  
      res.status(201).json({
          message : 'Post Added Successfully..!!!'
      });
  });
  
  app.get('/api/posts',(req,res,next)=&gt;{
  
      posts = [{id:'1',title:'Post1',content:'This is post1'},
              {id:'2',title:'Post2',content:'This is post2'}
              ];
  res.json({
      message : 'posts fetched successfully..!!',
      posts : posts
  });
  });
  
  
  module.exports = app;
  </code></pre>
  
  <p>Here is my server.js</p>
  
  <pre><code>  const app = require("./backend/app");
    const debug = require("debug")("node-angular");
    const http = require("http");
  
    const normalizePort = val =&gt; {
      var port = parseInt(val, 10);
  
      if (isNaN(port)) {
        // named pipe
        return val;
      }
  
      if (port &gt;= 0) {
        // port number
        return port;
      }
  
      return false;
    };
  
    const onError = error =&gt; {
      if (error.syscall !== "listen") {
        throw error;
      }
      const bind = typeof port === "string" ? "pipe " + port : "port " + port;
      switch (error.code) {
        case "EACCES":
          console.error(bind + " requires elevated privileges");
          process.exit(1);
          break;
        case "EADDRINUSE":
          console.error(bind + " is already in use");
          process.exit(1);
          break;
        default:
          throw error;
      }
    };
  
    const onListening = () =&gt; {
      const addr = server.address();
      const bind = typeof port === "string" ? "pipe " + port : "port " + port;
      debug("Listening on " + bind);
    };
  
    const port = normalizePort(process.env.PORT || "3000");
    app.set("port", port);
  
    const server = http.createServer(app);
    server.on("error", onError);
    server.on("listening", onListening);
    server.listen(port);
  </code></pre>
  
  <p>When I try without .save() function. Posts are successfully fetched to angular side from server and getting displayed in other component (which created wrote to display the entered posts. But, while using save method. Posts are not even displayed from server side). </p>