-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f98d68
commit 1dd5ab8
Showing
3 changed files
with
292 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |