-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
35 lines (32 loc) · 1.09 KB
/
server.js
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
const express = require('express');
const MongoClient = require('mongodb').MongoClient;
const app = express();
MongoClient.connect("mongodb://localhost:27017" , (err , client) => {
if(err) console.log("could'nt connect to Mongodb");
console.log("successfully connected to Mongodb on port 27017");
const db = client.db('Todos')
// db.collection("Todos").insertOne({
// text: "todo one",
// complited: false
// },(err , result) => {
// if(err) console.log('could not insert document!' , err);
// console.log(JSON.stringify(result.ops , undefined , 2) , "1 document added to collection")
// })
db.collection("Users").insertOne({
name: "Reza",
mail: "[email protected]",
age: 28,
location: "Tehran",
} , (err , result) => {
if(err) console.log(err);
console.log(result.ops[0]._id.getTimestamp());
})
client.close();
})
app.get('/' , (req , res) => {
res.send("Hello world!");
})
app.listen(3000 , ()=>{
console.log('application is running on localhost: 3000')
})
module.exports.app = app;