express js

react login api example

  const [isBookingDone, setIsBookingDone] = useState(false); const [isError, setIsError] = useState(false); const [errorMessage, setErrorMessage] = useState(”); const slotBooking = async (slotTiming, bookedDate, userId) => { let config = { url: `http://localhost:3005/api/bookings`, method: ‘POST’, headers: { ‘Content-Type’: ‘application/json’, }, data: { ‘slotTiming’: slotTiming, ‘bookedDate’: bookedDate, ‘userId’: userId }, }; await axios(config).then((res) => { loadBookingData(); setIsBookingDone(true); }).catch((e) …

react login api example Read More »

create jwt token

  var jwt = require(‘jsonwebtoken’); let user = { email: ‘userDetails.email’, firstName: ‘userDetails.firstName’, lastName: ‘userDetails.lastName’, userType: ‘userDetails.userType’, id: ‘userDetails.id’, } const expiresInSecs = 120; const token = jwt.sign({ data: user }, ‘secret_key’, { expiresIn: 60 * 60 }); console.log(‘ttttttttt’, token)

What is the “__v” field in Mongoose – remove that field

 const mongoose = require(‘mongoose’); const userSchema = new mongoose.Schema({ username: { type: String, // required: true, // unique: true }, email: { type: String, // required: true, // unique: true }, password: { type: String, }, firstname: { type: String, }, lastname: { type: String, }, address: { type: String, }, mobile: { type: String, …

What is the “__v” field in Mongoose – remove that field Read More »

How to fix the Express req.body undefined error

 Now, if we send a JSON data to the /users route, we will see an undefined in the console. To fix this error, first we need to parse our incoming requests by using the express.json() , express.urlencoded() middleware functions. const express = require(“express”); const app = express(); // middleware app.use(express.json()); app.use(express.urlencoded()); app.post(“/users”, (req, res) => { console.log(req.body); }); app.listen(3000, () => console.log(`App is …

How to fix the Express req.body undefined error Read More »