Skip to content

Instantly share code, notes, and snippets.

@devindianushika
Last active May 18, 2020
Embed
What would you like to do?
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