Skip to content

Commit 1a6ebc6

Browse files
committed
model is defined
1 parent e1c83e3 commit 1a6ebc6

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

CRUD API's/app.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const express=require('express');
22
const bodyparser=require('body-parser');
33
const mongoose=require('mongoose');
4+
const dburl=require('./database/myurl.js');
45

56
//create express app
67
const app=express();
@@ -12,7 +13,8 @@ app.use(bodyparser.json());
1213

1314
//connect the database
1415
mongoose.Promise=global.Promise;
15-
mongoose.connect('mongodb://localhost:27017/crud-api',{
16+
17+
mongoose.connect(dburl.url,{
1618
useNewUrlParser: true
1719
}).then(()=>{
1820
console.log("database is connected");
@@ -26,6 +28,7 @@ app.get('/',function(req,res){
2628
res.json({"message": "welcome to crud api's"});
2729
});
2830

31+
2932
const PORT=3000||process.env.PORT;
3033
app.listen(PORT,()=>{
3134
console.log(`app is live at ${PORT}`);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const mongoose=require('mongoose');
2+
3+
//defining schema
4+
const noteSchema=mongoose.Schema({
5+
title:{
6+
string
7+
}
8+
})

CRUD API's/database/app/routes/routes.js

Whitespace-only changes.

CRUD API's/database/myurl.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports={
2+
url:'mongodb://localhost:27017/crud-apis'
3+
}

0 commit comments

Comments
 (0)