Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mongodb node 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}`));
Comment

PREVIOUS NEXT
Code Example
Javascript :: vue is undefined vue 3 vue.use 
Javascript :: dom event 
Javascript :: js .reducer method 
Javascript :: how to set css in hbs in express 
Javascript :: use react awesome slider in react js 
Javascript :: react native flex 2 columns per row 
Javascript :: sort by ascending javascript 
Javascript :: javascript trigger keypress 
Javascript :: js string to blob 
Javascript :: typeof date 
Javascript :: Documenting inside javascript 
Javascript :: how to repeat string in javascript 
Javascript :: function prototype in javascript 
Javascript :: react onchange multiple functions 
Javascript :: boucle foreach js 
Javascript :: dull or blur a background image in react native 
Javascript :: remove a value to an array of javascript 
Javascript :: mongoose encrypt password 
Javascript :: p5.js how to display a text from string 
Javascript :: responseText js 
Javascript :: javascript how to open a file 
Javascript :: javascript loop 
Javascript :: mometjs 
Javascript :: js array.some 
Javascript :: c# convert object to json 
Javascript :: nested json schema mongoose 
Javascript :: multi-dimensional array js 
Javascript :: javascript goto page 
Javascript :: center canvas p5js 
Javascript :: javascript object get value by key 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =