Question

how to set legacy-peer-deps, getting error and unable to deploy my MERN application

How to fix it and best if someone can assist with the points, flow to deploy back-end and admin dashboard for a web application.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
May 12, 2023

Hi there,

To set legacy-peer-deps you need to modify the .npmrc file in your project. This file allows you to customize how npm behaves when running commands. If you don’t already have this file, you can create it in the root directory of your project.

Here is how you can do it:

  1. In the root directory of your project, create or open the .npmrc file.

  2. In the .npmrc file, add the following line:

    legacy-peer-deps=true
    
  3. Save and close the file.

Now, npm will use the old behavior for handling peer dependencies, which was to essentially ignore them unless --peer is explicitly provided to npm install.

For deploying your MERN application (MongoDB, Express.js, React.js, Node.js) on DigitalOcean, you can follow these steps:

  1. Create a new Droplet: From the DigitalOcean dashboard, create a new Droplet. Choose an image that includes Node.js or use a basic one like Ubuntu and install Node.js later.

  2. Transfer your application files: Transfer your application files to the Droplet. You can use a tool like scp or rsync for this. Or if you have a GitHub project, you can use the git clone command to clone your project on the Droplet.

  3. Install dependencies: SSH into your Droplet and navigate to your project directory. Run npm install to install your application’s dependencies. You may also need to install MongoDB if it’s not already installed.

  4. Set environment variables: If your application uses environment variables (for example, to connect to MongoDB), set these on your Droplet. You can do this in the terminal with export VAR_NAME=value, or by adding these lines to your ~/.bashrc or ~/.bash_profile file.

  5. Start your application: From your project directory, start your application with npm start. If you want your application to run in the background, consider using a process manager like pm2.

  6. Configure your firewall: If necessary, configure your Droplet’s firewall to allow traffic to the port your application is running on.

  7. Deploy the React Admin Dashboard: You can build your admin dashboard using npm run build or yarn build in your React project directory. This will create a build folder that contains the static files of your project which can be served by a web server. You can use nginx to serve these static files on DigitalOcean Droplet.

For a more in-depth tutorial, I would recommend following the steps here:

https://www.digitalocean.com/community/tutorials/getting-started-with-the-mern-stack

Also, for production, I would personally go with the DigitalOcean Managed Database clusters:

https://www.digitalocean.com/products/managed-databases-mongodb

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel
Get started for free

Enter your email to get $200 in credit for your first 60 days with DigitalOcean.

New accounts only. By submitting your email you agree to our Privacy Policy.

© 2023 DigitalOcean, LLC.