Created
March 31, 2020 18:26
-
-
Save vagnerlandio/c07a7c075f24c03ea014afd7bfeed9d0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const express = require("express"); | |
const mongoose = require("mongoose"); | |
const morgan = require("morgan"); | |
const bodyParser = require("body-parser"); | |
const cookieParser = require("cookie-parser"); | |
require("dotenv").config(); | |
// import routes | |
const userRoutes = require("./routes/user"); | |
// app | |
const app = express(); | |
// db | |
console.log(process.env.DATABASE); | |
mongoose | |
.connect( | |
"mongodb+srv://tay:[email protected]/test?retryWrites=true&w=majority", | |
{ | |
useNewUrlParser: true, | |
useCreateIndex: true, | |
useUnifiedTopology: true | |
} | |
) | |
.then(() => console.log("DB Connected")); | |
//middlewares | |
app.use(morgan("dev")); | |
app.use(bodyParser.json()); | |
app.use(cookieParser()); | |
//routes | |
app.use("/api", userRoutes); | |
const port = process.env.PORT || 8000; | |
app.listen(port, () => { | |
console.log(`O servidor está sendo executado na porta ${port}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment