GithubHelp home page GithubHelp logo

atlas_starter_nodejs's Introduction

MongoDB Atlas Node.js Sample Project

This repository contains an example application that connects to MongoDB Atlas using the Node.js MongoDB driver. You can use this application as a reference for when you build your Node.js application.

Prerequisites

To build and run this project, you need Node.js version 10 or later and a compatible version of NPM (Node Package Manager) installed. For information on how to check your version of Node and NPM, see the NPMJS page on downloading and installing Node.js and npm.

Getting Started

The following instructions explain how to get your project connected to your instance of MongoDB Atlas.

1. Download the Repository

To get started with this sample project, download this repository to your programming environment. You can clone this project using Git version control:

git clone https://github.com/mongodb-university/atlas_starter_nodejs.git

Or you can download the ZIP archive using your browser. If you download this project as a ZIP archive, unzip the archive before proceeding.

2. Install Depedencies

Navigate to the directory containing the project in your shell or open it in your preferred IDE.

Then, use the NPM dependency file that we included in the project directory called package.json to download and install your dependencies:

npm install

This command reads the package.json file and downloads and saves the dependencies defined within it to a directory called node_modules. It also creates a package-lock.json file that sets the version information for each of the modules required to build your project.

At this point, you should have appropriate versions of Node.js and NPM installed as well as a project directory that contains the dependencies you need to use the Node.js MongoDB driver.

3. Configure your Atlas Credentials

  1. Open the app.js file.

  2. Search for the variable uri near the top which is assigned placeholder text. Replace the placeholder text with the connection string for your Atlas cluster. For more information on finding the connection string, see Connect via Driver in the Atlas documentation.

    const uri = 
      "<Your Atlas Connection String>";
  1. Save the changes to your app.js file.

4. Run the Project

If you are running from the shell, you can run the application from the directory that contains it with the following command:

node app

If you are running it from the IDE, use the appropriate command to run the contents of the app.js file.

  1. Click the Run icon, or from the Run menu, choose Start Debugging.

Assuming you have the correct connection string, you have now connected the Node app to your MongoDB Atlas datastore. Have fun modifying the code to experiment with the Node driver and MongoDB.

Troubleshooting

Are you having trouble getting connected to your MongoDB Atlas instance? Double-check the following:

  1. Have you replaced the uri variable with a valid connection string provided by the Atlas UI? Read more here for further context.

  2. Have you added your current IP address to the access list in the Atlas UI?

atlas_starter_nodejs's People

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.