Nó MongoDB JS
var http = require('http');
var express = require('express')
var app = express()
var path = require('path')
var bodyParser = require('body-parser')
app.use(express.static(path.join(__dirname,"/dist")));
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// Route to Homepage
app.get('/', (req, res) => {
res.sendFile(__dirname + '/attendance/index.html');
});
// POST /login gets urlencoded bodies
app.post('/login', (req, res)=> {
console.log(req.body.usernames, req.body.passwords)
MongoClient.connect(url, (err, db)=> {
if (err) throw err;
var dbo = db.db("mydb");
var query = { username: req.body.usernames,password: req.body.passwords };
dbo.collection("account_tbl").find(query).toArray(function(err, result) {
if (err){
throw err;
}
else{
console.log("Res",err);
res.send(result);
}
db.close();
});
});
})
const port = 3000
app.listen(port, () => console.log(`This app is listening on port ${port}`));
Tropapeeps TV