From a28324a0fdd24b026c226dc98b53de7210a0ad4f Mon Sep 17 00:00:00 2001 From: Nestor Sebastian Garzon Contreras Date: Sun, 18 Oct 2020 20:20:09 -0500 Subject: [PATCH] rest server usuario --- server/config/config.js | 17 +++++++++++++++++ server/routes/user.js | 2 +- server/server.js | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/server/config/config.js b/server/config/config.js index 9c32e05..838de59 100644 --- a/server/config/config.js +++ b/server/config/config.js @@ -3,3 +3,20 @@ //====================== process.env.PORT = process.env.PORT || 3000 + +//====================== +//Entorno +//====================== +process.env.NODE_ENV = process.env.NODE_ENV || 'dev' + +//====================== +//DB +//====================== + +let urlDB; +if (process.env.NODE_ENV === 'dev') { + urlDB = 'mongodb://127.0.0.1:27017/waffly' +} else { + urlDB = 'mongodb+srv://admin-nw:Sebastian1@cluster0.txwjd.mongodb.net/waffly' +} +process.env.URLDB = urlDB; \ No newline at end of file diff --git a/server/routes/user.js b/server/routes/user.js index d5a02d2..d331445 100644 --- a/server/routes/user.js +++ b/server/routes/user.js @@ -14,7 +14,7 @@ app.get('/usuario', function (req, res) { if (err) { return res.status(400).json({ ok: false, err }) } - Usuario.count({ estado: true }, (err, counter) => { + Usuario.estimatedDocumentCount({ estado: true }, (__, counter) => { res.json({ ok: true, counter, usuarios }) }) }) diff --git a/server/server.js b/server/server.js index 58ea47b..69dbfe0 100644 --- a/server/server.js +++ b/server/server.js @@ -10,7 +10,7 @@ app.use(bodyParser.json()) app.use(require('./routes/user')) -mongoose.connect('mongodb://127.0.0.1:27017/waffly', { +mongoose.connect(process.env.URLDB, { useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false,