

Wait_for " and close the file when you are finished adding the code.įirst, define the nodejs application service by adding the following code to the file:

Usage 1 esac done if thenĮchoerr "Error: you need to provide a host and port to test." Open the project’s package.json file using nano or your favorite editor:īeneath the project dependencies and above the closing curly brace, create a new devDependencies object that includes nodemon: This repository includes the code from the setup described in How To Integrate MongoDB with Your Node Application, which explains how to integrate a MongoDB database with an existing Node application using Mongoose.Ĭlone the repository into a directory called node_project: Running the application with nodemon ensures that it will be automatically restarted whenever you make changes to your code.įirst, clone the nodejs-mongo-mongoose repository from the DigitalOcean Community GitHub account. You will add nodemon to the project’s devDependencies, specifying that you will be using it during development. The first step in building this setup will be cloning the project code and modifying its package.json file, which includes the project’s dependencies. Step 1 - Cloning the Project and Modifying Dependencies Docker Compose installed on your server, following Step 1 of How To Install Docker Compose on Ubuntu 18.04.Docker installed on your server, following Steps 1 and 2 of How To Install and Use Docker on Ubuntu 18.04.For guidance on how to set these up, please see this Initial Server Setup guide.

A development server running Ubuntu 18.04, along with a non-root user with sudo privileges and an active firewall.Create a user and password-protected database for the application’s data.Īt the end of this tutorial, you will have a working shark information application running on Docker containers:.Ensure that changes to the application code work without a restart.Synchronize the application code on the host with the code in the container to facilitate changes during development.Because this application works with Node and MongoDB, your setup will do the following: You will create two containers - one for the Node application and another for the MongoDB database - with Docker Compose. This tutorial will show you how to set up a development environment for a Node.js application using Docker. Environments are portable, allowing you to package and share your code with others.Environments are isolated, making it easier to troubleshoot issues and onboard new team members.Environments are consistent, meaning that you can choose the languages and dependencies you want for your project without worrying about system conflicts.Working with containers in development offers the following benefits: If you are actively developing an application, using Docker can simplify your workflow and the process of deploying your application to production.
