title: How to deploy express.js server to Netlify
body: <p>I am attempting to deploy a Vue.js, Node, Express, MongoDB (MEVN) stack application to Netlify. I successfully deployed the front end of the application to Netlify, and am now attempting to deploy the express server, based on the following <code>serverless-http</code> example: <a href="https://github.com/neverendingqs/netlify-express/blob/master/express/server.js" rel="noreferrer">https://github.com/neverendingqs/netlify-express/blob/master/express/server.js</a></p>
  
  <p>I configured my server to include the <code>serverless-http</code> package:</p>
  
  <p>server.js</p>
  
  <pre><code>const express = require('express');
  const app = express();
  const serverless = require('serverless-http');
  const bodyParser = require('body-parser');
  const cors = require('cors');
  const mongoose = require('mongoose');
  const config = require('./DB.js');
  const postRoute = require('./routes');
  
  mongoose.connect(config.DB, { useNewUrlParser: true, useUnifiedTopology: true }).then(
    () =&gt; { console.log('Database is connected') },
    err =&gt; { console.log('Can not connect to the database'+ err)}
  );
  
  app.use(cors());
  app.use(bodyParser.urlencoded({extended: true}));
  app.use(bodyParser.json());
  
  app.use('/messages', postRoute);
  
  app.use('/.netlify/functions/server', router);  // path must route to lambda
  app.use('/', (req, res) =&gt; res.sendFile(path.join(__dirname, '../public/index.html')));
  
  
  module.exports = app;
  module.exports.handler = serverless(app);
  
  </code></pre>
  
  <p>routes.js</p>
  
  <pre><code>const express = require('express');
  const postRoutes = express.Router();
  
  // Require Post model in our routes module
  let Post = require('./post.model');
  
  // Defined store route
  postRoutes.route('/add').post(function (req, res) {
    let post = new Post(req.body);
    post.save()
      .then(() =&gt; {
        res.status(200).json({'business': 'business in added successfully'});
      })
      .catch(() =&gt; {
        res.status(400).send("unable to save to database");
      });
  });
  
  // Defined get data(index or listing) route
  postRoutes.route('/').get(function (req, res) {
      Post.find(function(err, posts){
      if(err){
        res.json(err);
      }
      else {
        res.json(posts);
      }
    });
  });
  
  module.exports = postRoutes;
  
  </code></pre>
  
  <p>I then re-deployed my application to Netlify, but the server does not seem to run in Netlify. This server is in a folder in project root of my vue.js app. Should I instead run the server as a separate site in Netlify? If not, what should I do in order to get the server to run when deployed in Netlify?</p>