Relative Content

Tag Archive for node.jsmongodbexpress

How to handle multiple requests (Express.js) with mongodb insert operation

Context I am following a tutorial which is titled “Building a Secure User Registration and Login API with Express.js ,MongoDB and JWT” It uses express bcryptjs jsonwebtoken mongoose to build a simple web server with register/login functionality. The problem The problem arise when I send a multitude of requests to /api/register. Server creates many users […]

Node.js Express MongoDB is not connecting

var express = require(‘express’); var router = express.Router() var MongoClient = require(‘mongodb’).MongoClient /* GET home page. */ router.get(‘/’, function(req, res, next) { res.render(‘index’, { title: ‘Express’ }); }); router.post(‘/submit’, (req, res, next)=>{ MongoClient.connect(‘mongodb://localhost:27017’, function(err, client){ if(err){ console.log(‘Error’) }else{ console.log(‘DB Connected’) } res.send(req.body) }) }) module.exports = router; I was trying to connect to the database, […]