diff --git a/.gitignore b/.gitignore index 327bcb6..7c4cdc7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules package-lock.json +credentials.js .env* \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..b31bc3a --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# Our MongoDB Api + +This project showcases what we've learned to make an api that will access a "movie" collection in our mongoDB database + +## To get started + +1) Clone it locally and run ```npm i``` (in the terminal) to install all dependencies +2) rename the ```credentials-example.js``` to ```credentials.js``` and edit the ```uri``` string to either be the one you get from your own cloud.mongodb.com cluster (under the "connect" button) OR you can us ```mongodb://localhost:27017``` if you want to connect to a local instance. +3) you can add new movies by sending a valid JSON body to```http://localhost:4001/add-movie``` and get movies by going to ```http://localhost:4001/get-movies``` diff --git a/credentials-example.js b/credentials-example.js new file mode 100644 index 0000000..36f3134 --- /dev/null +++ b/credentials-example.js @@ -0,0 +1 @@ +export const uri = ' replace this string (from quote to quote) with the full string from cloud.mongodb.com or mongodb://localhost:27017 like we had before ' diff --git a/mongoConnect.js b/mongoConnect.js index c2092e7..c4b37fc 100644 --- a/mongoConnect.js +++ b/mongoConnect.js @@ -2,8 +2,15 @@ import { MongoClient } from 'mongodb' import dotenv from 'dotenv' dotenv.config() +// If you'll be using the credentials then rename the credentials-example.js to credendials.js and add your info +// import { uri } from "./credentials.js" + +// If you're connecgting to your local server on your laptop +// const uri = 'mongodb://localhost:27017' + +// If you're using the .env file with a MONGO_URI entry const uri = process.env.MONGO_URI -// uri = 'mongodb://localhost:27017' + const client = new MongoClient(uri) // creating client mongo instance const db = client.db('bocacode-test') // connecting to db = bocacod-test diff --git a/readme.md b/readme.md index 2b30080..97c3050 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,12 @@ # Node API with MongoDb +This project showcases what we've learned to make an api that will access a "movie" collection in our mongoDB database + +## To get started 1. After cloning project install dependencies with `npm i` 2. Connect to MongoDB (if local start with `brew services start mongo-community) -3. Run API with nodemon \ No newline at end of file +3. Run API with nodemon + +## How to use it: +you can add new movies by sending a valid JSON body to```http://localhost:4001/add-movie``` and get movies by going to ```http://localhost:4001/get-movies``` +