Making Mongoose work with Express

Hi there!

I am able to get an Express server working with this tutorial:

Here is my WORKING example:
https://spiffy-bubblegum-56dac1.netlify.app/.netlify/functions/api

But when I try to add Mongoose I get this:
https://kingpong-server.netlify.app/.netlify/functions/api

Are there extra steps to deploying an express server that uses mongoose to call a mongo database?

Thanks in advance!
Tim

Edit: To clarify, when I run the express server on my local it works perfectly.

If I’m not wrong, shouldn’t this:

be router.get()? That’s what you’ve done in the example that works. You also need to configure your app to use the router.

I figured it out, there were two issues, both causing the function calls to take more than 10 seconds so it was timing out.

The first issue was the simplest, I hadn’t allowed any IP address to query the database on my MongoDB dashboard.

The second issue was I hadn’t set my handler up properly to interact with asynchronous functions (which mongoose uses).
Here is the code I used to fix it:

Before:

module.exports.handler = serverless(app);

After:

const handler = serverless(app);
module.exports.handler = async (event, context) => {
  const result = await handler(event, context);
  return result;
};

Thanks for the tip! I figured it out before, so apologies I thought I’d responded on here already!