-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
91 lines (77 loc) · 2.19 KB
/
server.js
File metadata and controls
91 lines (77 loc) · 2.19 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
'use strict';
const express = require('express');
const path = require('path');
global.Vue = require('vue');
// Get the HTML layout
//const layout = fs.readFileSync('./index.html', 'utf8');
// Create a renderer
const renderer = require('vue-server-renderer').createRenderer();
// App
const server = express();
// Serve files from the assets directory
//server.use('/assets', express.static(
// path.resolve(__dirname, 'assets')
//));
//
//app.get('/', function(req, res){
// res.send("haaiii");
//});
//
//// Listen on port 5000
//server.listen(3000, error => {
// if (error) throw error;
//
// console.log('Server is running at localhost:3000');
//});
var MongoClient = require('mongodb').MongoClient
,assert = require('assert');
// Connection URL
var url = `mongodb://mongo:27017/MEVN`;
var insertDocuments = function(db, callback) {
// Get the documents collection
var collection = db.collection('documents');
// Insert some documents
collection.insertMany([
{a : 1}, {a : 2}, {a : 3}
], function(err, result) {
assert.equal(err, null);
assert.equal(3, result.result.n);
assert.equal(3, result.ops.length);
console.log("Inserted 3 documents into the collection");
callback(result);
});
}
var findDocuments = function(db, callback) {
// Get the documents collection
var collection = db.collection('documents');
// Find some documents
collection.find({}).toArray(function(err, docs) {
assert.equal(err, null);
console.log("Found the following records");
console.log(docs)
callback(docs);
});
}
var updateDocument = function(db, callback) {
// Get the documents collection
var collection = db.collection('documents');
// Update document where a is 2, set b equal to 1
collection.updateOne({ a : 2 }
,{ $set: { b : 1 } }, function(err, result) {
assert.equal(err, null);
assert.equal(1, result.result.n);
console.log("Updated the document with the field a equal to 2");
callback(result);
});
}
// Use connect method to connect to the server
MongoClient.connect(url, function(err, db) {
assert.equal(null, err);
console.log("Connected successfully to server");
db.close();
//insertDocuments(db, function() {
// updateDocument(db, function() {
// db.close();
// });
//});
});