Vite, Express, MongoDB, Netlify

Hi there,

Im quite new to netlify, and got a problem with deploying a project.

I’ve came across a great pre-setup of vite with express, and got it connected to mongodb atlas.

My problem is, I’m not sure how to integrate that with netflify’s framework.

The vite-express is from a github repo, it basically integrates a project so that it runs an express server and the vite frontend simultaneously.

I got the setup to work on local environment wih your cli (netlify-cli, latest version), using env tables, and simply by

  • copying the code I’ve had in the vite-express’s src/server/main.ts to netlify/functions/api.ts
  • changing the package.json to run following:
"scripts": {
    "dev": "nodemon netlify/functions/api.ts -w netlify/functions",
    "start": "SET NODE_ENV=production & ts-node netlify/functions/api.ts",
    "build": "vite build"
  },

The problem is when the netlify online deployment starts and finishes, as far as I can tell from the console and Network tab, whenever I try to make a request to the express api framework, it shows its not connected to the mongodb, and seems like the express env stopped or didnt even start due to an error.

Could you tell me either how to set this up correctly, or how to test it on local environment with the same build? Again, in local env, using the netlify dev command, everything works correctly.

@LarryTest21 Please don’t make duplicate posts.

This has been answered in your other thread here: