z3r0Luck
5 years ago
1 changed files with 0 additions and 47 deletions
@ -1,47 +0,0 @@ |
|||||
|
|
||||
|
|
||||
// declaring dependencies |
|
||||
const express = require('express'); |
|
||||
const bodyParser= require('body-parser') |
|
||||
const app = express(); |
|
||||
// Make sure you place body-parser before your CRUD handlers! |
|
||||
app.use(bodyParser.urlencoded({ extended: true })) |
|
||||
|
|
||||
// Constants |
|
||||
const PORT = 8080; |
|
||||
const HOST = '0.0.0.0'; |
|
||||
|
|
||||
var MongoClient = require('mongodb').MongoClient; |
|
||||
var connectionString = "mongodb://10.0.5.3:27017/"; |
|
||||
|
|
||||
MongoClient.connect(connectionString, { useUnifiedTopology: true }) |
|
||||
.then(client => { |
|
||||
console.log('Connected to Database') |
|
||||
const db = client.db('cloudDB') |
|
||||
const quotesCollection = db.collection('mycollection') |
|
||||
|
|
||||
|
|
||||
|
|
||||
app.post('/quotes', (req, res) => { |
|
||||
quotesCollection.insertOne(req.body) |
|
||||
.then(result => { |
|
||||
res.redirect('/') |
|
||||
}) |
|
||||
.catch(error => console.error(error)) |
|
||||
}) |
|
||||
|
|
||||
app.get('/', (req, res) => { |
|
||||
const cursor = db.collection('quotes').find().toArray() |
|
||||
.then(results => { |
|
||||
console.log(results) |
|
||||
}) |
|
||||
res.sendFile(__dirname + '/index.html') |
|
||||
}) |
|
||||
|
|
||||
app.listen(PORT, HOST); |
|
||||
|
|
||||
}) |
|
||||
|
|
||||
|
|
||||
console.log(`Running on http://${HOST}:${PORT}`); |
|
||||
|
|
Loading…
Reference in new issue