nodejs

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 »

nodejs multiple module exports

Module file file name – operator.js const add = (a, b)=>{ return a +b ; } const sub = (a, b)=>{ return a – b ; } const name =‘kanha’; module.exports = {add, sub , name}; index file – where you are importing the modules  filename = index.js const op = require(‘./operator’); console.log(op.add(2,5)); console.log(op.sub(2,5)); console.log(op.name);