-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule1.js
More file actions
67 lines (54 loc) · 1.32 KB
/
module1.js
File metadata and controls
67 lines (54 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const mongoose =require('mongoose');
const express = require('express');
var app = express();
mongoose.connect('mongodb://localhost/LibraryDB')
.then(()=> console.log('connected module1'))
.catch(err=>console.error('err'))
const bookSchema=new mongoose.Schema({
ISBN : String,
Title : String,
Author : String,
Publisher : String,
Image : String,
FA : String,
Count : Number,
AC :Number,
desc : String,
pc : Number
});
const BookDb = mongoose.model('BookDb', bookSchema);
async function createBook(){
const Book=new BookDb({
ISBN : "898456",
Title :" bunksheet",
Author : "nitin",
Publisher : "amey",
Image : "kwrgrgar",
FA : "no",
Count : 10,
AC :8500,
desc : "lsajgmal;eg, amgl",
pc : 10
});
const result= await Book.save();
console.log(result);
}
// for(var i = 0; i < 100;i++){
// createBook();
// }
// async function getBooks(){
// const books=await BookDb.find();
// console.log(books);
// }
// getBooks();
app.get('/listBooks', (req, res) => {
async function getBooks(){
const books=await BookDb.find().limit(10);
console.log(books);
res.send(books, () => {
console.log(' ');
})
}
getBooks();
});
app.listen(3000);