Skip to content

Commit

Permalink
adds mongoose test file
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobKnaack committed Mar 11, 2024
1 parent 6f98d68 commit 1dd5ab8
Show file tree
Hide file tree
Showing 3 changed files with 292 additions and 0 deletions.
242 changes: 242 additions & 0 deletions class-11/demo/pokedex-backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions class-11/demo/pokedex-backend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "pokedex-backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^16.4.5",
"mongoose": "^8.2.1"
}
}
34 changes: 34 additions & 0 deletions class-11/demo/pokedex-backend/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

const mongoose = require('mongoose');
const dotenv = require('dotenv');
dotenv.config();

const DATABASE_URL = process.env.DATABASE_URL;

// modeling our Problem Domain?

// figure out how to implement our idea
// what properties or keys are being stored, what values do those map to
let pokemonSchema = new mongoose.Schema({
name: String,
type: String,
health: Number,
attack: Number,
});


mongoose.connect(DATABASE_URL)
.then(confirmation => {
console.log("CONNECTION ESTABLISHED!!");

// mongoose wants to feed schemas into model constructors
let Pokemon = mongoose.model('pokemon', pokemonSchema);

const pikachu = new Pokemon({ name: 'Pikachu' });
pikachu.save();
console.log(pikachu);
})
.catch(e => {
console.error('CONNECTION ERROR', e);
});

0 comments on commit 1dd5ab8

Please sign in to comment.