I'm on a project using a stack that includes PostgreSQL, NodeJS, SailsJS, and BackboneJS. I pulled the client and server repos from git and I navigate into the server for the project and try to run it:
sails lift
Then I get this error:
/Users/$USER/Documents/Code/$APP/config/adapters.js:39
host: mc.dbSettings.host,
TypeError: Cannot read property 'host' of undefined
Where mc is a var that is set to point to another mainConfig.js file using a require statement. Opening that file I see that dbSettings is defined as:
dbSettings: {
host: "localhost",
user: "_appName_",
password: "_password_",
dbName: "_appDB_"
},
and sails cannot initialize because there is no localhost, or it doesn't know what it is? Please help.
If you're requireing a file and getting an "undefined" error trying to access its contents, it's possible you haven't exported the file contents properly. Your config file should look something like:
module.exports = {
dbSettings: {
host: "localhost",
user: "_appName_",
password: "_password_",
dbName: "_appDB_"
},
...
};
Note the module.exports. If that's missing, or if it's namespaced (like module.exports.foo) or if that dbSettings object is nested inside something else, it won't work.
dbSettings is undefined. So that must mean that it's not being found by SailJS. If you are using v.1.0 then you need to define your settings in connections.js instead of adapters.js. I'm assuming Sails will not be able to find your configuration otherwise.
Related
I want to initialize a MySQL connection with credentials that i'm getting from a master database, is possible to do this on AdonisV4?
using adonis lucid
I can't set the credentials in config, because they're specific for every request that is made.
You would invoke npm library related to mysql in terminal shell.
npm i --save mysql
AdonisJs uses the connection value defined inside the config/database.js file. Thus, you may to create a configuration file for a single database connection in your JavaScript application like following:
You can create an initial environment file for your master database like :
HOST=127.0.0.1
PORT=3306
NODE_ENV=development
CACHE_VIEWS=false
For several connections, you would setup your config file like this:
'use strict'
const Env = use('Env')
const Helpers = use('Helpers')
module.exports = {
connection: Env.get('DB_CONNECTION', 'mysql1'),
mysql1: {
client: 'mysql',
connection: {
host: Env.get('DB_HOST', 'database_host_1'),
port: Env.get('DB_PORT', '3306'),
user: Env.get('DB_USER', 'my_database_user_1'),
password: Env.get('DB_PASSWORD', 'OhMyAdonis'),
database: Env.get('DB_DATABASE', 'adonis')
}
},
mysql2: {
client: 'mysql',
connection: {
host: Env.get('DB_HOST', 'database_host_2'),
port: Env.get('DB_PORT', '3306'),
user: Env.get('DB_USER', 'my_database_user_2'),
password: Env.get('DB_PASSWORD', 'OhMySecondAdonis'),
database: Env.get('DB_DATABASE', 'another_adonis')
}
}
}
So, you can select any of the connections defined by the database configuration file at runtime with:
Database
.connection('mysql1')
.table('users')
Database
.connection('mysql2')
.table('users')
However, if yo have a lot of databases, this approach impacts the RAM server. So, if you have a master database like your case, choose connection dynamically following an ORM for Node.JS using a SQL query builder like Objection.js with knex - based support for MySQL.
A multitenancy approach could be adopted from here.
I hope you can help!
I have setup and Amazon echo applcation, the application makes a request to and AWS EC2 instance and gets JSON data as a response, this is working as expected however the use case for the final application is to connect to a private IP sending paramaters to an API to return the same JSON DATA.
for many reasons sadly I cannot share any of the endpoint information.
I need my NODE.js Application to make a request to the private IP over a VPN connection, Im currently using OPENVPN to make local requests to the endpoint.
I have looked at node packages to see if this is possible but I cannot seem to find one, except for this package here
https://www.npmjs.com/package/node-openvpn
This package is has a dependancy thats fails to download, so i got the node_module manually but Im getting an error when i try to execute the code
var openvpnmanager = require('node-openvpn');
var opts = {
host: 'xx.xx.xx.xx', // normally '127.0.0.1', will default to if undefined
port: 443, //port openvpn management console
timeout: 1500, //timeout for connection - optional, will default to 1500ms if undefined
logpath: 'log.txt' //optional write openvpn console output to file, can be relative path or absolute
};
var auth = {
user: '*******',
pass: '*******',
};
var openvpn = openvpnmanager.connect(opts)
openvpn.on('connected', function() { //will be emited on successful interfacing with openvpn instance
openvpnmanager.authorize(auth);
});
openvpn.on('console-output', function(output) { //emits console output of openvpn instance as a line
console.log(output)
});
openvpn.on('state-change', function(state) { //emits console output of openvpn state as a array
console.log(output)
});
// openvpnmanager.getLog(console.log) //get all console logs up to this point
// and finally when/if you want to
// openvpnmanager.disconnect();
openvpn.on('disconnected', function() { //emits on disconnect
openvpnmanager.destroy() //finally destroy the disconnected manager
});
this just gives me an error
Unhandled rejection TypeError: Cannot read property 'writable' of undefined
at Telnet.exec (C:\Users\user\Desktop\alexa- po\node_modules\node-openvpn\node_modules\telnet-client\lib\telnet- client.js:90:24)
If anybody has any suggetions on how to make this possible I would be very grateful.
I am trying to connect to OriendDB(v2.0.13) using Orientjs(v2.0.0) on NodeJS(v0.12.2) like so:
var OrientDB = require('orientjs');
var orientDBServer = OrientDB({
host: 'localhost',
port: 2424,
username: 'orientdb',
password: 'orientdb'
});
var database = orientDBServer.use({
name: 'thermos',
username: 'orientdb',
password: 'orientdb'
});
As soon as I make a query, for example:
database.select().from('OUser').all()
.then(function(result) {
console.log(result);
});
I'm getting this error.
Unhandled rejection OrientDB.ConnectionError [1]: Remote server closed
the connection.
at Connection.handleSocketEnd (/usr/share/adafruit/webide/repositories/my-pi-projects/Thermostat/node_modules/orientjs/lib/transport/binary/connection.js:320:9)
at Socket.emit (events.js:104:17)
at _stream_readable.js:908:16
at process._tickCallback (node.js:355:11)
I tried different query just to make sure I'm not doing a mistake myself and I also tried via studio and the console directly on the server which worked fine. (using the same logins...)
What can possibly cause this error?
Thanks
Update
I made a second nodejs server and now I can successully make requests on the database that is installed on the first server. I'll investigate if there is some sort of weird permission that blocks localhost or if node is missing some kind of permission...(first server is running raspbian)
I don't think you have to specify the username and password again for the use function. My database config file looks like this and it works like a charm :
var OrientDB = require('orientjs');
var server = OrientDB({
host:'localhost',
port:2424,
username: 'root',
password: 'root'
});
module.exports = server.use('databaseName');
Also, make sure that you created the database with the account you are using. Otherwise, it won't work.
If this still doesn't work, it could be a bug. I would personally try recreating the database...
After days of running in circles I finally found that if I remove another library that I am using, everything works fine... (library causing the conflict is GrovePi). I'll continue investigating to find the root of the issue. Thanks for your help Alex.
I consistently get a SequelizeConnectionRefusedError when trying to connect to a MySQL database on my server.
The login credentials are correct, the port is open, everything seems good (and works like a charm in the dev environment).
Sorry for the scarce background information, but I'm dumbfounded here - I really don't know what could be causing this problem.
This is my output from mysql --version
mysql Ver 14.14 Distrib 5.5.43, for debian-linux-gnu (x86_64) using readline 6.3
And this is the code I'm using to initialize Sequelize. The table I want it to use doesn't exist yet, but I'm fairly sure that hasn't got anything to do with this problem. I've tried logging in with the root user as well, but no dice - I still get the same error.
var sequelize = new Sequelize("database", username, password, {
host: "localhost",
dialect: "mysql",
port: 3306,
define: {
paranoid: true
}
});
var Model = sequelize.define("Model", {
md5: {type: Sequelize.STRING(128)},
ip: {type: Sequelize.STRING(256)},
url: {type: Sequelize.STRING(1024)}
});
sequelize.sync();
This is running on Ubuntu 14.04, where node is being run behind Passenger (although the error appears if I run the application with node directly as well). I'm running nginx and PHP on the same server, where another PHP application is connecting to the database, if that's of any relevance.
What could be causing this problem?
I tried to connect to the database directly with the MySQL module as well, but that gave me the same error. When looking for solutions to the same problem, but related to the MySQL module rather than Sequelize, I found this: connect ECONNREFUSED - node js , sql.
What I needed was to supply the mysql module with a socketPath key. Here's how I changed my code to make it work:
var sequelize = new Sequelize("database", username, password, {
host: "localhost",
dialect: "mysql",
logging: function () {},
pool: {
max: 5,
min: 0,
idle: 10000
},
dialectOptions: {
socketPath: "/var/run/mysqld/mysqld.sock"
},
define: {
paranoid: true
}
});
We're having difficulty setting up a Heroku/Postgres database with Knex running our queries. We've set up our heroku/postgres db and created our tables, but we're having difficulty connecting to it with Knex. To make matters worse, there's almost no documentation on connecting Heroku/Postgres with Knex or any ORM so trying to figure this stuff out has been a real pain.
These are the connection patterns that I've tried.
var knex = require('knex')({
client: 'pg',
connection: {
user: username,
password: password,
host: host,
port: port,
database: database,
ssl: true
}
}
});
And... Note the ssl true was toggle and removed all together to no avail.
var knex = require('knex')({
client: 'pg',
connection: HEROKU_POSTGRESQL_COLOR_URL,
ssl: true
}
});
We've also tried this pattern as well:
var pg = require('knex')({
client: 'pg',
connection: HEROKU_POSTGRESQL_COLOR_URL
});
We haven't yet pulled down a copy of our localdb, so every test we run is basically a git commit. We're basically testing an insert query on a GET request to our root (index.html) page. So on any get request to the main page, it should insert something into our waterrates table. If I switch it from insert to select, it returns an object but you can't actually see any of the data in the object.
The inserts we're attempting to use are:
knex.select('*').from('waterrates').then(function(rows){
return rows;
});
knex('waterrates').insert({name: 'pleeeaseee work'}, {rate: 100}).then(function(rows){
console.log(rows);
})
knex.select().
We're actually uncertain where the error could be as attempting to connect doesn't yield any errors. It's probably something silly, but we have no idea where/how to troubleshoot this. Any help would be greatly appreciated!
Thanks,
B
I had an old version of PG installed which was causing the issue. We changed our package.json file to use the latest PG. Heroku updated it and it worked!
As a side note, if anyone looks at this in the future, heroku requires an SSL connection. Keep that in mind when you're working. The connection string that I provided above should work for you all.
B
For anyone who is dealing with this problem.
Please set "SSL" to false if you don't use paid dynos.
Heroku only assigns "SSL" to users who use paid dynos.
const db = knex({
client: 'pg',
connection: {
connectionString : process.env.DATABASE_URL,
ssl: false
}
});