Skip to content

Instantly share code, notes, and snippets.

@devindianushika
Last active May 18, 2020 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devindianushika/6611ea6a21f6772d1482e0b08a9872d3 to your computer and use it in GitHub Desktop.
Save devindianushika/6611ea6a21f6772d1482e0b08a9872d3 to your computer and use it in GitHub Desktop.
connect with Mongodb
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