-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
27 lines (25 loc) · 780 Bytes
/
index.js
File metadata and controls
27 lines (25 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import express from 'express'
import mongoose from 'mongoose'
import accountsRouter from './routes/accounts.js'
// Usado para encapsular variaveis
import dotenv from 'dotenv'
dotenv.config()
// cria uma instancia do express
const app = express()
// usar formato json no express
app.use(express.json())
//Rota para os metodos HTTP
app.use("/accounts", accountsRouter)
app.listen(process.env.PORT, async () =>{
try {
await mongoose.connect('mongodb+srv://'+process.env.USERDB+':'+process.env.PWDB+'@trabalho-modulo-4.z8e52.mongodb.net/Accounts?retryWrites=true&w=majority',
{
useNewUrlParser: true,
useUnifiedTopology: true,
}
);
console.log('API Inicializada!!!')
} catch (error) {
console.log('Erro ao conectar no MongoDB' + error);
}
})