Initial commit.
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
**/node_modules
|
||||
12
app.js
Normal file
12
app.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const express = require('express');
|
||||
const Mongo = require('./mongo');
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
|
||||
|
||||
app.get('/test', (request, response) => {
|
||||
const mongoClient = new Mongo();
|
||||
})
|
||||
|
||||
app.listen(port, () => console.log('Mock is listening at port ', port, '\n'));
|
||||
27
mongo.js
Normal file
27
mongo.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const mongodb = require('mongodb');
|
||||
const assert = require('assert');
|
||||
|
||||
const mongoConfig = {
|
||||
url: 'mongodb://localhost:27017',
|
||||
username: 'express-user',
|
||||
password: 'P@ssword1',
|
||||
database: 'express-test'
|
||||
}
|
||||
|
||||
class Mongo {
|
||||
constructor() {
|
||||
mongodb.MongoClient.connect(mongoConfig.url, (err, client) => {
|
||||
assert.equal(null, err);
|
||||
console.log('Connected successfuly to mongodb');
|
||||
this.db = client.db(mongoConfig.database);
|
||||
|
||||
this.db.collection('test').find({}, (err, results) => {
|
||||
results.forEach(console.log);
|
||||
});
|
||||
|
||||
client.close();
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Mongo;
|
||||
2321
package-lock.json
generated
Normal file
2321
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
22
package.json
Normal file
22
package.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "ExpressJS",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "nodemon ./app.js localhost 3000",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"express": "^4.17.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^7.4.0",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"nodemon": "^2.0.4",
|
||||
"mongodb": "^3.6.1"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user