Skip to content

Commit

Permalink
CORS y Express
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardVargasPilarte committed Mar 22, 2022
0 parents commit 83fa36f
Show file tree
Hide file tree
Showing 7 changed files with 1,494 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
4 changes: 4 additions & 0 deletions README.md
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
18 changes: 18 additions & 0 deletions database/config.js
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
};
30 changes: 30 additions & 0 deletions index.js
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';
Loading

0 comments on commit 83fa36f

Please sign in to comment.