Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express');
- const app = express();
- app.use(express.json());
- app.use(express.urlencoded());
- const MongoClient = require('mongodb').MongoClient;
- const assert = require('assert');
- const url = 'mongodb://anil:Passw0rd@ds225543.mlab.com:25543/mymongodb';
- app.get('/', (req, res) => {
- res.sendFile(__dirname + '/index.html');
- });
- app.post('/login', (req, res) => {
- console.log(req.body);
- var username = req.body.username;
- var password = req.body.password;
- MongoClient.connect(url, function(err, database) {
- if(err) { return console.dir(err); }
- const mymongodb = database.db('mymongodb')
- var collection = mymongodb.collection('login')
- collection.findOne({user: username}, function(err, document) {
- var db_password = document.password;
- if(password == db_password) {
- res.send('Login successful.');
- } else {
- res.send('Login failed.');
- }
- });
- });
- });
- app.listen(3000, () => console.log('Gator app listening on port 3000!'));
Add Comment
Please, Sign In to add comment