Category : express

Hi I am trying to run a standard example from the supertest package. const request = require(‘supertest’); const express = require(‘express’); const app = express(); app.get(‘/user’, function(req, res) { res.status(200).json({ name: ‘john’ }); }); request(app) .get(‘/user’) .expect(‘Content-Type’, /json/) .expect(‘Content-Length’, ’15’) .expect(200) .end(function(err, res) { if (err) throw err; }); It crashes with an Operation timed ..

Read more

I am creating a login system using React JS, Node JS(Express, Express-session, cookieParser, bodyParser, express-vaidator, pg, bcrypt and cors ) and PostgresSQL! I am try creating session to save data from de users and control the acess permission but a session shouldn’t view in browser This is the code from my route: app.post(‘/login’,[ body("emailInput").isEmail().normalizeEmail().withMessage(‘Este não ..

Read more

I’m setting an httpOnly cookie after login in a user with bcrypt. router.post(‘/login’, (req, res) => { User.findOne({email: req.body.email}, function(err, user) { if (err) throw err; if (user) { user.comparePassword(req.body.password, function(err, isMatch) { if (err) throw err; let token = jwt.sign({ id: user._id }, process.env.SECRET_KEY, {expiresIn: ’24h’}); res.cookie(‘token’, token, {maxAge: 60*1000, httpOnly: true, secure: true}) ..

Read more

I’m trying to create a simple web app with NodeJs and express-handlebars . But Images are not displaying properly in my html page which I’m rendering using handlebars. Below is my app structure MyApp is root folder -images -views -layouts -main.hbs -home.hbs -index.js -package.json project structure My index.js contains below code const express = require(‘express’); ..

Read more

here’s the code router.delete("/deleteUser/:id", function (req, res) { console.log("User deleted — "); User.findOneAndDelete(req.params.id, function (err, deleted) { if (err) { res.send("error deleting"); } else { res.json(deleted); } }); }); and when i try the url http://localhost:5000/Users/deleteUser/6106ab9c08bf5717b827aa39 in postman says the requested resource could not be found but may be available again in the future Source: ..

Read more