Last active
May 18, 2020 18:53
-
-
Save devindianushika/6611ea6a21f6772d1482e0b08a9872d3 to your computer and use it in GitHub Desktop.
connect with Mongodb
This file contains 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 app = express(); | |
const port = 3000; | |
const mongoose = require('mongoose'); | |
const config = require ('./config/database'); | |
const routeuser = require('./routes/routeuser'); | |
const bodyParser = require('body-parser'); | |
const connection = mongoose.connect(config.database, { | |
useNewUrlParser: true, useUnifiedTopology: true }); | |
if(connection){ | |
console.log("database connected"); | |
} | |
else{ | |
console.log("database connection error"); | |
} | |
//request read as json | |
app.use(bodyParser.urlencoded({ extended: false })) | |
// parse application/json | |
app.use(bodyParser.json()) | |
app.use("/user",routeuser); | |
app.get("/",function(req,res){ | |
res.end("hello world"); | |
}) | |
app.listen(port,function(){ | |
console.log("server is " + port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment