Skip to content

Commit

Permalink
update env settings
Browse files Browse the repository at this point in the history
  • Loading branch information
henriqueyang committed Sep 2, 2019
1 parent f1f80e4 commit e69166b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
APP_URL=http://localhost:3000
MONGO_URL=mongodb://localhost:27017/nodeAPI
PORT=3000
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
npm-debug.log
yarn-error.log
.env
22 changes: 0 additions & 22 deletions package.json

This file was deleted.

7 changes: 3 additions & 4 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ const cors = require('cors');

const mongoose = require('mongoose');
const requireDir = require('require-dir');
require('dotenv-safe').config({ allowEmptyValues: true });

const app = express();
app.use(express.json()); // Permitir request de dados em formato JSON
app.use(cors()); // Permite acesso da API aos domínios externos

// Iniciando o Database
mongoose.connect('mongodb://localhost:27017/nodeAPI', { useNewUrlParser: true })
mongoose.connect(process.env.MONGO_URL, { useNewUrlParser: true })
.then(() => console.log('MongoDB connected'))
.catch(error => console.log('Connection failed: ' + error));
mongoose.set('useFindAndModify', false);
Expand All @@ -19,6 +20,4 @@ requireDir('./models');
// Rotas
app.use('/api', require('./routes'));

app.listen(3000, () => {
console.log('server on')
});
app.listen(process.env.PORT || 3000, () => console.log('server on'));

0 comments on commit e69166b

Please sign in to comment.