Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to share variables between routes node

var router = require("express").Router()

var varSetMiddleware = function(res,req,next){
  router.variable = 100
  // set the variable inside the router object 
  // now you can access it anywhere in this specific router
  next()
}

router.get("/first_view", function (req, res) {
  // something  
  console.log(router.variable) //100
  res.send("something")
})

router.get('/second_view', function (req, res) {
  // something
  console.log(router.variable) //100
  res.send("something")

module.exports = router
Comment

PREVIOUS NEXT
Code Example
Javascript :: import NativeMethodsMixin from "NativeMethodsMixin"; error 
Javascript :: URIError 
Javascript :: exchange array.include(string) in Javascript to array.indexOf(string) == -1 in Typescript 
Javascript :: angular taskkill in port 4200 
Javascript :: distructuring null check 
Javascript :: moment format escape 
Javascript :: react-leaflet/core/cjs/pane.js:7%20error15-Jun-2021%2000:45:06%20%20%20%20%20%20const%20pane%20=%20props.pane%20??%20context.pane; 
Javascript :: scrollreveal react tutoriel 
Javascript :: How to unmount inactive screens in bottom tab react native 
Javascript :: https://www.npmjs.com/package/number-in-letters 
Javascript :: how to pass argument in onFinish method in antdesign 
Javascript :: mongoose geospatial Schema Options 
Javascript :: underscore filter array of objects 
Javascript :: import image in react js 
Javascript :: sort 
Javascript :: format large texts 
Javascript :: close responsive menu after click 
Javascript :: allow cookies sent by the client 
Javascript :: micromodal scrolls to bottom 
Javascript :: javascript make the web browser scroll to the top 
Javascript :: javascript map api key insert 
Javascript :: javascript source code for digital meter 
Javascript :: convert utc time to specific timezone javascript 
Javascript :: convert to arrow functions 
Javascript :: k6 control a live k6 test 
Javascript :: how to make model class for complex json in flutter 
Javascript :: switch is not exported from react-router-dom 
Javascript :: react router dom link same page with different param 
Javascript :: misturar dois arrays javascript 
Javascript :: next js global layout 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =