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

  • Home
  • SEARCH
  • 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 7036515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:26:00+00:00 2026-05-28T01:26:00+00:00

Currently I’m setting my client connection for node-mysql by doing the following in my

  • 0

Currently I’m setting my client connection for node-mysql by doing the following in my app.js and a special config/environment.js:

var client = mysql.createClient({
  user:     'USER',
  database: 'DATABASE',
  password: 'PASSWORD',
  host:     'HOST'
});

app.configure(function(){
  ...
  app.set('client', client);
  ...
});

Then in my client code I just call app.settings.client to use the MySQL client.

I’m not sure if this is the right approach, and it certainly doesn’t work when I’m doing testing, as I need a running instance of the app.

Any suggestions?

  • 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-28T01:26:01+00:00Added an answer on May 28, 2026 at 1:26 am

    There are 3 solutions the way I see it:

    a) As @Raynos suggested in the comments, use app.set(key, value); to set a db value and then app.set(key) to get that value.
    b) Wrap your routes into a function that accepts the database as a parameter.
    Example:

    sample_route.js

    module.exports = function (db) {
      return function(req, res, next) {
        // db is accessible here
      }
    }
    

    app.js

    var = sample_route = require('./sample_route')(db);
    app.get('/sample', sample_route);
    

    c) Make a global variable that will be accessible everywhere (not recommended though): global.MY_DB = ...;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I using the following code to get my JSON output from MySQL. <?php
Currently I'm doing some unit tests which are executed from bash. Unit tests are
Currently I'm doing a project whose specifications are unclear - well who doesn't. I
Currently I am debugging the signing of an Android app. And this would be
Currently, I have: <html> <div class=yes1><span><img src=img></span></div> </html> <script> var x = ='yes1' var
currently I'm developing an app for WP7 but came across a little problem with
Currently have the following expression: @[TMS_Dest] + \\ + @[TMS_Rename] + (DT_WSTR,4)DatePart(yyyy, GetDate()) +
Currently, most of the popular websites, like google, yahoo detect if the user connection
Currently I am developing a Mac OS X app with XCode 3.2.5 on Mac
Currently local storage for javascript is limited to cookies, which makes robust client side

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.