Categories
Mastering Development

Node js form submit TypeError: Cannot set property ‘userId’ of undefined

I have added login and registration features to a page in my application in views/employee/login.hbs. When I enter in registration details (email, username, password and conf password), I hit the register button to hopefully be redirected to the views/employee/home.hbs page. However, when I complete this action my MongoDB Compass Community database receives the registration details […]

Categories
Mastering Development

Mongoose cannot set property of ” ” to undefined,Whenever i try to create a new entry.Eventhough the schema is declared right

im building a support portal webiste.Where i have to record which user is raising the ticket. Im using passport so i can get the username and _id through req.user.Im using express and MongoDB Atlas as my database.I have saved my database schemas on a seaparate folder called models. Here is the schema file: const mongoose=require(“mongoose”); […]

Categories
Mastering Development

How do i update a object in mongoDB via nodeJS?

I’m attempting to make it so that when a player gets a highscore it searches there name, then it adds that highscore to there account. My issue is I don’t know how to search for a name and update a tag using mongoose? Here is my server code: var mongoose = require(“mongoose”); var bodyParser = […]

Categories
Mastering Development

Deleting a post with Ajax, Node and Express. How do i delete a post with Ajax

I am trying to delete my blogpost with Ajax, Node and Express, but for unknown reason it’s not working. It was working initially when i had all my codes inside index.js file. but after separating them into Model and routes, it suddenly stopped finding the route or whatever the problem might be. I have these […]

Categories
Mastering Development

MongoDB Atlas connection keeps dropping

I’ve integrated MongoDB atlas to my nodejs application, but the connection keeps dropping every few hours, which is forcing the app to restart. Is there a away to handle reconnections in the code to avoid restart of the app ? { MongoNetworkError: connection 2 to 67.156.445.93:27017 closed at (anonymous function).forEach.op (/home/ubuntu/app/node_modules/mongodb/lib/cmap/connection.js:63:15) at Map.forEach () at […]

Categories
Mastering Development

Passport.js ‘Unauthorized’ when attempting login

I attempted to integrate Passport.js as authorization for my website, but every time I login with valid user credentials, it return Unauthorized. I have included all the files that contain any passport code, but my project has more files, I hope these won’t interfere with Passport.js at all. app.js const express = require(‘express’); const ejs_express_layouts […]

Categories
Mastering Development

Express gives the same response even with different input-values in MongoDB

I’m new learning Express and MongoDB. I’m following an Udemy course, and I’m sure that my code is exactly the same. My problem: When I post some data to a MongoDB collection, it works as expected. But when I try to add a new value, it works, but inserts the same value that the first […]

Categories
Mastering Development

express-session does not delete session in mongodb

account.js (node.js part) const express = require(“express”); const router = express.Router(); router.post(“/logout”, (req, res) => { console.log(“session: “, req.session); req.session.destroy(); console.log(“session: “, req.session); res.send(true); }) session: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZTZjZjJiNDY1N2Q3MjQzNzQxMzFjODkiLCJpYXQiOjE1ODQ3MDM3MDF9.A8-gorvV3SI7boHGbtiRh6NXHbnYIR1VnsAzNWwwMTw session: undefined Purpose: User login process is successful. If the login is successful, it saves the information to the mongodb field. Problem: When I write the line of […]

Categories
Mastering Development

“express-session deprecated undefined resave option; provide resave option node_modules/admin-bro-expressjs/plugin.js:138:14”

am using admin-bro for my admin , it works fine until i try to use its authentication, when i try to login to the admin using the admin-bro login form dashboard ,it just keeps loading with no response,my terminal says express-session deprecated undefined resave option; provide resave option node_modules/admin-bro-expressjs/plugin.js:138:14 express-session deprecated undefined saveUninitialized option; provide […]

Categories
Development

object value coming undefined in node controller function

I’ve created a contact form with angular 7 and integrated it with nodemailer so that upon submitting the form the details of the form should be submitted to an specified email. The view is working fine and passing the values perfectly, but when the values are sent to the node backend it’s coming as undefined […]