-
Notifications
You must be signed in to change notification settings - Fork 0
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
RichardVargasPilarte
committed
Mar 22, 2022
0 parents
commit 83fa36f
Showing
7 changed files
with
1,494 additions
and
0 deletions.
There are no files selected for viewing
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,2 @@ | ||
PORT=3005 # default port to listen | ||
DB_CONNECTION_STRING=mongodb+srv://Richard_Vargas:Dq7v9YIsMueuJeAy@cluster0.q00gh.mongodb.net/HospitalDB # default mongo connection string |
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 @@ | ||
node_modules/ |
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,4 @@ | ||
# Hospital MEAN Backend | ||
|
||
Recuerda ejecutar npm install para instalar las dependecias | ||
Y para iniciar el servidor ejecuta npm run start:dev |
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,18 @@ | ||
const mongoose = require('mongoose'); | ||
require('dotenv').config(); | ||
|
||
const dbConnection = async () => { | ||
try { | ||
await mongoose.connect(process.env.DB_CONNECTION_STRING, { | ||
|
||
}); | ||
console.log('Connection succsessful'); | ||
} catch (error) { | ||
console.error(error); | ||
throw new Error('Error trying to connect'); | ||
} | ||
} | ||
|
||
module.exports = { | ||
dbConnection | ||
}; |
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,30 @@ | ||
require('dotenv').config(); // import dotenv | ||
|
||
const express = require('express'); // import express | ||
const cors = require('cors'); // import cors | ||
|
||
const { dbConnection } = require('./database/config'); // import dbConnection from config.js | ||
|
||
// Crear server de express | ||
const app = express(); // create an instance of express | ||
|
||
app.use(cors()); // enable cors | ||
|
||
// Base de datos | ||
dbConnection(); // connect to database | ||
|
||
// Rutas | ||
app.get('/', (req, res) => { | ||
res.json({ | ||
ok: true, | ||
mensaje: 'Petición realizada correctamente' | ||
}); | ||
}); | ||
|
||
app.listen(process.env.PORT, () => { | ||
console.log('listening on port' + process.env.PORT); // listen process.env.PORT | ||
}); | ||
|
||
|
||
// username = 'Richard_Vargas'; | ||
// password = 'Dq7v9YIsMueuJeAy'; |
Oops, something went wrong.