I'm learning Sails JS (and NodeJS), and I'm trying to set a connection to SQL Server Express. What I have so far:
A database called test-project-db with a table inside called TestTable1. It has two columns: name varchar(20) and description varchar(100).
A sails project generated with sails new, and a model/component made with sails generate api TestTable1.
My files:
- api/models/TestTable1.js
module.exports = {
attributes: {
name: {
type: 'string',
},
description: {
type: 'string',
},
}
};
- config/connections.js:
sqlserver: {
adapter : 'sails-sqlserver',
user : 'sa',
password: 'passw',
host : 'localhost\\SQLEXPRESS',
database: 'test-project-db'
}
- config/models.js:
module.exports.models = {
connection: 'sqlserver',
migrate: 'safe',
};
But when I run the server with sails lift and go to localhost:1337/testtable1, I get the error:
(node:15756) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): ConnectionError: Failed to connect to localhost:undefined in 60000ms
(node:15756) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
And, if instead of sails-sqlserver I use sails-mssqlserver, I get (in the console):
{"name":"Sails-MSSqlserver","hostname":"DESKTOP-PMN0K03","pid":15928,"level":30,"msg":"Error in __FIND__: { ConnectionError: Failed to connect to localhost:undefined in 60000ms\n at Connection.<anonymous> (D:\\Práctica 2\\test-project\\node_modules\\sails-mssqlserver\\node_modules\\mssql\\lib\\tedious.js:378:25)\n at Object.onceWrapper (events.js:315:30)\n at emitOne (events.js:116:13)\n at Connection.emit (events.js:211:7)\n at Connection.connectTimeout
(D:\\Práctica 2\\test-project\\node_modules\\sails-mssqlserver\\node_modules\\tedious\\lib\\connection.js:467:12)\n at ontimeout (timers.js:475:11)\n at tryOnTimeout (timers.js:310:5)\n at Timer.listOnTimeout (timers.js:270:5)\n name: 'ConnectionError',\n message: 'Failed to connect to localhost:undefined in 60000ms',\n code: 'ETIMEOUT' }","time":"2018-01-31T19:00:27.325Z","v":0}
error: Sending 500 ("Server Error") response:
Error (E_UNKNOWN) :: Encountered an unexpected error
ConnectionError: Failed to connect to localhost:undefined in 60000ms
at Connection.<anonymous> (D:\Práctica 2\test-project\node_modules\sails-mssqlserver\node_modules\mssql\lib\tedious.js:378:25)
at Object.onceWrapper (events.js:315:30)
at emitOne (events.js:116:13)
at Connection.emit (events.js:211:7)
at Connection.connectTimeout (D:\Práctica 2\test-project\node_modules\sails-mssqlserver\node_modules\tedious\lib\connection.js:467:12)
at ontimeout (timers.js:475:11)
at tryOnTimeout (timers.js:310:5)
at Timer.listOnTimeout (timers.js:270:5)
Details: ConnectionError: Failed to connect to localhost:undefined in 60000ms
And in the browser:
[Error (E_UNKNOWN) Encountered an unexpected error] Details: ConnectionError: Failed to connect to localhost:undefined in 60000ms
Along a 500 error page.
Any idea on what am I doing wrong?
localhost:undefined --> The port is undefined because you didn't provide it in the configuration. Add in the port attribute into your sqlserver connection within config/connections.js, and assign it your database server's port.
Side note: learning Sails while learning Node is quite a handful, especially since Sails can look intimidating at first. Just take it piece by piece, and you'll definitely get a hang of it. If you're familiar with MVC frameworks, such as Rails, then Sails will feel right at home.
Related
I'm trying to make a mineflayer bot but it seems to keep sending the same error. Here is the code:
const mineflayer = require('mineflayer')
const bot = mineflayer.createBot({
host: 'localhost',
port: ,
username: 'Test_Bot'
})
And here is the error:
Error: Unsupported brand channel name
at getBrandCustomChannelName (/Users/jeonghunchae/Desktop/Bots/node_modules/mineflayer/lib/plugins/game.js:22:11)
at inject (/Users/jeonghunchae/Desktop/Bots/node_modules/mineflayer/lib/plugins/game.js:67:24)
at /Users/jeonghunchae/Desktop/Bots/node_modules/mineflayer/lib/plugin_loader.js:41:7
at Array.forEach (<anonymous>)
at injectPlugins (/Users/jeonghunchae/Desktop/Bots/node_modules/mineflayer/lib/plugin_loader.js:40:16)
at EventEmitter.onInjectAllowed (/Users/jeonghunchae/Desktop/Bots/node_modules/mineflayer/lib/plugin_loader.js:12:5)
at Object.onceWrapper (node:events:627:28)
at EventEmitter.emit (node:events:513:28)
at Client.next (/Users/jeonghunchae/Desktop/Bots/node_modules/mineflayer/lib/loader.js:124:9)
at Object.onceWrapper (node:events:627:28)
jeonghunchae#2015017 Bots %
Is there any way how I can fix this error?
First I tried to make a lan server in my world and it sent this error. Then I created a private server with online-mod: false but it still sent the same error.
I had the same Problem.
After a lot of research I found that I was not sure if my minecraft Version(1.19.2) was supported by Mineflayer.
After switching to 1.19 the error Message was gone.
I am new to node.js and mongoDB Atlas. I am having an issue connecting to Mongo Atlas using the Node.js version 3.0 or later connection string.
const MongoDB = 'mongodb+srv://<user>:<password>#cluster0-nnezr.mongodb.net/<dbname>?retryWrites=true&w=majority'
When I use this connection string I get the following error -
MongoDB connection error: Error: querySrv ETIMEOUT _mongodb._tcp.cluster0-nnezr.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (dns.js:203:19) {
errno: undefined,
code: 'ETIMEOUT',
syscall: 'querySrv',
hostname: '_mongodb._tcp.cluster0-nnezr.mongodb.net'
}
(node:38809) UnhandledPromiseRejectionWarning: Error: querySrv ETIMEOUT _mongodb._tcp.cluster0-nnezr.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (dns.js:203:19)
(Use node --trace-warnings ... to show where the warning was created)
(node:38809) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside ofan async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:38809) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections thatare not handled will terminate the Node.js process with a non-zero exit code.
I have found a workaround using the previous connection string for node.js version 2.2.12 -
mongodb://<user>:<password>#cluster0-shard-00-00-nnezr.mongodb.net:27017,cluster0-shard-00-01-nnezr.mongodb.net:27017,cluster0-shard-00-02-nnezr.mongodb.net:27017/<dbname>?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true&w=majority
When connecting I have to add {useUnifiedTopology: true}
mongoose.connect(mongoDB, { useNewUrlParser: true, useUnifiedTopology: true });
Can anyone give me a little insight on what im doing wrong with the new connection string?
Thanks!
have write user, password and maybe also database ,
const MongoDB = 'mongodb+srv://<user>:<password>#cluster0-nnezr.mongodb.net/<dbname>?retryWrites=true&w=majority'
user = your mongodb user name
password = your mongodb password
dbname = Database name
and don't forget to create a new user in MongoDB atlas.
I am trying to connect to Heroku's database via NodeJs.
I tried to connect to localhost and it worked perfectly. But when i tried to remote database it gives error.
Here is the localhost connection code which is working perfectly.
const conectionString='postgressql://postgres:1234#localhost:5433/Qfield'
const client= new Client({
connectionString:conectionString
})
client.connect()
//client.query('select * from point',(err,res)=>{
// console.log(err,res)
// client.end()
//})
client.query('SELECT * FROM trees', function(err, res) {
console.log(err,res)
client.end()
});
Here is the error connection which is remote database.
const {Pool,Client}=require('pg')
const conectionString='postgressql://Username:Password#ec2-54-228-243-29.eu-west-1.compute.amazonaws.com:5432/database'
const client= new Client({
connectionString:conectionString
})
client.connect()
//client.query('select * from point',(err,res)=>{
// console.log(err,res)
// client.end()
//})
client.query('SELECT * FROM trees', function(err, res) {
console.log(err,res)
client.end()
});
Here is the error.
(node:14896) UnhandledPromiseRejectionWarning: error: no pg_hba.conf entry for host "193.140.225.88", user "vfoiltyjszbpav", database "dduigib0uc8ebt", SSL off
at Connection.parseE (C:\Users\CBS Lab\Desktop\postgres_conn\node_modules\pg\lib\connection.js:604:11)
at Connection.parseMessage (C:\Users\CBS Lab\Desktop\postgres_conn\node_modules\pg\lib\connection.js:401:19)
at Socket.<anonymous> (C:\Users\CBS Lab\Desktop\postgres_conn\node_modules\pg\lib\connection.js:121:22)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
(node:14896) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:14896) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Error: Connection terminated unexpectedly
at Connection.con.once (C:\Users\CBS Lab\Desktop\postgres_conn\node_modules\pg\lib\client.js:252:9)
at Object.onceWrapper (events.js:286:20)
at Connection.emit (events.js:198:13)
at Socket.<anonymous> (C:\Users\CBS Lab\Desktop\postgres_conn\node_modules\pg\lib\connection.js:131:10)
at Socket.emit (events.js:203:15)
at endReadableNT (_stream_readable.js:1145:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
How can I fix this error? What am I doing wrong?
Add ssl=true to your connection string to fix the error you've got:
const conectionString='postgressql://Username:Password#ec2-54-228-243-29.eu-west-1.compute.amazonaws.com:5432/database?ssl=true'
Scenario 1: postgres service not running. node start. rest calls times out => no issues
Scenario 2: postgres service not running. node start. postgres service start. rest calls work => no issues
Scenario 3: postgres service not running. node start. postgres service start. rest calls work. postgres service stop => node crash.
Stack trace when this happens is given below:
error: terminating connection due to administrator command
at Connection.parseE (...\express.js\node_modules\pg\lib\connection.js:553:11)
at Connection.parseMessage (...\express.js\node_modules\pg\lib\connection.js:378:19)
at Socket. (...\express.js\node_modules\pg\lib\connection.js:119:22)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at Socket.Readable.push (_stream_readable.js:208:10)
at TCP.onread (net.js:594:20)
I am using Postgres Pool with the following config:
const pool = new Pool({
user: 'postgres',
host: 'localhost',
database: 'sampleDB',
password: 'password',
port: 5432,
max: 1,
idleTimeoutMillis: 30000,
connectionTimeoutMillis: 2000,
})
How do I handle this case so that node won't crash and can go back to Scenario-1 and then move to Scenario-2 ?
After going through the documentation of node-postgres(link), I figured out a way to capture this error and avoid node crash.
pool.on('error', (err, client) => {
console.log('postgres connection error : ' + err)
})
Adding the above code will allow node to handle the error and not crash.
I am getting the following error while connecting to the MongoDB through Node.js.
Error:
process.nextTick(function() { throw err; })
^
Error: connect UNKNOWN 127.0.0.1:27017 - Local (undefined:undefined)
at Object.exports._errnoException (util.js:870:11)
at exports._exceptionWithHostPort (util.js:893:20)
at connect (net.js:843:14)
at net.js:939:9
at doNTCallback0 (node.js:419:9)
at process._tickCallback (node.js:348:13)
I am running the my MongoDB using the command mongod --dbpath C:\new --journal.I am explaining my code below.
var mongo=require('mongojs');
var database='medilink';
var collections=['admin','supplier'];
var db=mongo("localhost:27017/"+database, collections);
Here i have one login app.When user is trying to login the above error is coming.Please help me to resolve this error.