Code Monkey home page Code Monkey logo

contact-bank's Introduction

Deployment of a MERN app in Render

In your project

  1. Folder structure

Store your react app in a folder named client in the root of your server project.

  1. Install dependencies
  • npm install concurrently nodemon
  1. Add script to server package.json

You will want to keep scripts to run your server and your client apps separately("start", "client").

Also you will want to keep script for development and for production ("dev", "deploy").

   "scripts": {
     "start": "node server.js",
     "server": "nodemon server.js",
     "client": "npm start --prefix client",
     "clientinstall": "npm install --prefix client",
     "dev": "concurrently \"npm run server\" \"npm run client\"",
     "deploy":"concurrently \"npm run server\" \"npm run client\"",
     "render-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
   }

Both apps will run in the same port, this will prevent CORS policy to apply. We will use concurrently to run both at the same time.

To deploy with Docker

Add a Dockerfile to your project root

FROM node:18-alpine
WORKDIR /app
COPY . .
RUN npm install 
WORKDIR /app/client
RUN npm install && npm run build
WORKDIR /app
CMD ["npm", "run", "deploy"]
EXPOSE 8080

In Render

  1. Go to Render

  2. Sign Up/Sign In, and go to your dashboard and click on New +

  3. Select Web Service

  4. On the right, click connect account beneath git and connect your git account and give appropriate permissions for your repository (or allow all).

  5. Click on Connect to connect your repository.

  6. Fill out your deployment settings.

  • Name: As you wish
  • Region: Choose the closest to your users.
  • Branch: The gitHub branch from which you'll be deploying
  • Root Directory: Leave as it is
  • Runtime: Node
  • Build command, you must install dependencies and build your client app: npm install && cd client && npm install && npm run build
  • Start command: npm run deploy
  • Autodeploy: Yes
  • Deploy hook: Leave as it is

To deploy with Docker, Render will detect automatically your Dockerfile in your root and set up the settings.

  1. Click on advanced

Add your environment variables

MY_MONGO_URI=*****
NODE_ENV='production'

or upload your .env

  1. Deploy

You can visit a deployed version of this proejct here

contact-bank's People

Contributors

gregpetropoulos avatar guille-rubio avatar

Stargazers

Fran V. Hdez. avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.