1
I have a mysql.js file that accesses the database as below:
'use strict';
var mysql = require('mysql'),
config = require('config');
var connection = mysql.createConnection({
host: config.get('mysql.server'),
user: config.get('mysql.username'),
password: config.get('mysql.password'),
database: config.get('mysql.database'),
port: config.get('mysql.port')
});
connection.connect(function (err) {
if (err) {
console.error('Error connecting: ' + err.stack);
return;
}
console.log('Connection established');
});
module.exports = connection;
I am using the config module (config.get(mysql.server), for example) to fetch the database access data according to the model below (default.json) located at the application root within a folder called config:
{
"mysql": {
"database": "BANCODEDADOS",
"password": "SENHA",
"port": "PORTA",
"server": "SERVIDOR",
"username": "USUARIO"
}
}
I’m using Visual Studio to work on this project.
What’s going on...
When I press F5 inside the vscode, it usually works by accessing the bank and other resources. No problems!
When I go to give a Restart inside vscode (Ctrl + Shit + F5), it gives an error in the connection stating that it was not possible to find the information in the default.json file (file where I have the access credentials as print above. (config.get(mysql.server) is Undefined, for example) and so the config module returns me a Undefined error:
node --debug-brk=21502 --nolazy www
Debugger listening on [::]:21502
WARNING: No configurations found in configuration directory:c:\Users\claudio.campos\Documents\Arquivos\Outros\Estudos\Projetos\Site\Aplicacao\bin\config
WARNING: To disable this warning set SUPPRESS_NO_CONFIG_WARNING in the environment.
c:\Users\claudio.campos\Documents\Arquivos\Outros\Estudos\Projetos\Site\Aplicacao\node_modules\config\lib\config.js:181
throw new Error('Configuration property "' + property + '" is not defined');
^
Error: Configuration property "mysql.server" is not defined
at Config.get (c:\Users\claudio.campos\Documents\Arquivos\Outros\Estudos\Projetos\Site\Aplicacao\node_modules\config\lib\config.js:181:11)
at Object.<anonymous> (c:\Users\claudio.campos\Documents\Arquivos\Outros\Estudos\Projetos\Site\Aplicacao\db\mysql.js:7:18)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (c:\Users\claudio.campos\Documents\Arquivos\Outros\Estudos\Projetos\Site\Aplicacao\routes\categoria.js:5:13)
Can anyone tell me why this only happens when I give a Re-start on vscode?
Put code here and not pictures pf. When you say
F5
referring to the browser? or restarting the server?– Sergio
I edited the question! F5 refers to vscode, but for example, I have the debug in the code, only I want to give a Restart in vscode... theoretically recites the server yes. All this happens just to give a re-start.
– cmcampos86