Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6022727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:54:01+00:00 2026-05-23T03:54:01+00:00

I am using nodejs and the node-mysql driver. I find myself doing repetitive boiler

  • 0

I am using nodejs and the node-mysql driver. I find myself doing repetitive boiler plate such as

client.query(querystr, queryparams, function callback(err, results, fields){

     if (err){ do err related stuff }
     else { do success related stuff }

}

Bottom-line most of the time everything is straightforward and repeated except what happens on success which varies wildly depending on the query and context.
So I’d like to encapsulate all this in a single function and pass in a querystr, queryparams and a success function.

Problem: I can’t do this as this is inside a callback and I cant make the query engine use my success function even if I pass it in via the callback arguments.

So I am thinking can I do a “require” inside the callback and if so will the functions in the “required” module be added to the global scope or the callback scope? I am hoping the latterB

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:54:02+00:00Added an answer on May 23, 2026 at 3:54 am

    You can assign variables to module scope, which is an approximation of ‘global’ like this:

    function a() { module.sys = require("sys"); }
    function b(cb) { cb() };
    b(a);
    console.log(sys);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using node-mysql driver for a node.js app. Instead of having to set-up
I am building an app on node.js using express, and node-mysql driver. There is
I am using node-mysql module ( https://github.com/felixge/node-mysql ) OR ( http://utahjs.com/2010/09/22/nodejs-and-mysql-introduction/ ) . Is
I'm doing a simple UDP send using Node's inbuilt datagram UDP socket : http://nodejs.org/docs/v0.3.1/api/dgram.html
I'm trying to connect to MySQL database from node.js using db-mysql library. Everything works
I'm using NodeJS to run a socket server (using socket.io). When a client connects,
Is there a way to find all nodes in a xml tree using cElementTree?
Using ASP.NET MVC there are situations (such as form submission) that may require a
I'm working with a tree structure in MySQL that is respresented using the nested
I'm using a forum with several topics and node comments module to add comment

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.