limestone module in Nodejs throwing error with nodejs and sphinx - node.js

I have been trying to connect sphinx server with nodejs and limestone module. But it is throwing error as follows. Please help me on this.
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: ENOENT, No such file or directory
at doConnect (net.js:549:5)
at Socket.connect (net.js:709:5)
at Object.createConnection (net.js:265:5)
at Object.connect (/home/node/node_modules/limestone/limestone.js:129:23)
at Object.<anonymous> (/home/node/www/bmchat-new/sphinx-connect.js:4:15)
at Module._compile (module.js:411:26)
at Object..js (module.js:417:10)
at Module.load (module.js:343:31)
at Function._load (module.js:302:12)
at Array.<anonymous> (module.js:430:10)
Source code of sphinx-connect.js
var limestone = require("limestone").SphinxClient(),
sys = require("sys");
limestone.connect("192.168.2.168:9312", // port. 9312 is standard Sphinx port. also 'host:port' allowed
function(err) { // callback
if (err) {
sys.puts('Connection error: ' + err);
}
sys.puts('Connected, sending query');
limestone.query(
{'query':'test', maxmatches:1},
function(err, answer) {
limestone.disconnect();
sys.puts("Extended search for 'test' yielded " +
answer.match_count + " results: " +
JSON.stringify(answer));
});
});

The issue is that i am using old limestone.js which i have got from npm(v1.0.106). So the updated one, you can get from github
Issue found is, old limestone.js using server_conn = tcp.createConnection(port); instead of the below one server_conn = tcp.createConnection(port, host);

Related

Unhandled rejection TypeError when trying to promisify a node-mysql connection and query

I'm attempting to use bluebird's promisify with the node-mysql package. Node version is 4.2.4
var Promise = require('bluebird');
var mysqlClient = Promise.promisifyAll(require("mysql/lib/Connection").prototype);
Promise.promisifyAll(require("mysql/lib/Pool").prototype);
var connectionOptions = ({
host: 'localhost',
user: 'root',
password: '',
database: 'my_db'
});
var firstPost = "some sql here";
var results = [];
mysqlClient.connectAsync(connectionOptions).then(function(connection){
connection.query(firstPost, function(){
console.log('i reached line 26 of a node script. a minor miracle')
});
}).catch(function(err) {
console.log(err);
});
I get the error
[TypeError: Cannot read property 'socketPath' of undefined]
Stack trace:
Unhandled rejection TypeError: Cannot read property 'socketPath' of undefined
at Connection.connect (/vagrant/spam_smasher/node_modules/mysql/lib/Connection.js:87:32)
at Connection.tryCatcher (/vagrant/spam_smasher/node_modules/bluebird/js/release/util.js:11:23)
at Connection.ret [as connectAsync] (eval at <anonymous> (/vagrant/spam_smasher/node_modules/bluebird/js/release/promisify.js:184:12), <anonymous>:13:39)
at Object.<anonymous> (/vagrant/spam_smasher/bluebird.js:24:13)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Function.Module.runMain (module.js:467:10)
at startup (node.js:136:18)
at node.js:963:3
Why am I getting this error and/or how could I debug it further? I tried to remote debug it but am not sure what I'm looking at when I get a few steps down the prototype chain. The Async functions do appear to be attached to the MysqlClient object.
Remore debugging reveals that the following section in node-mysql's Connection.js file is throwing the error :
if (!this._connectCalled) {
this._connectCalled = true;
// Connect either via a UNIX domain socket or a TCP socket.
this._socket = (this.config.socketPath)
? Net.createConnection(this.config.socketPath)
: Net.createConnection(this.config.port, this.config.host);
socketpath is not something you need to define when using node-mysql directly
It seems the Bluebird docs are out of date. They miss that you also need ConnectionConfig to be available and so this was missing in my code, causing the error.
I chose to abandon this problem to preserve my sanity. There is further discussion here and you may also want to check out mysql-promise

Can't write to a spawned child_process's stdin on Windows

The below code works fine on linux, but breaks on Windows 7
var spawn = require('child_process').spawn;
var sass = spawn('sass');
sass.stdout.on('data', function (data) {
console.log('' + data);
});
sass.stdin.write('.asdfsadf\n color: red', function () {
sass.stdin.end()
});
The error I get is
events.js:72
throw er; // Unhandled 'error' event
^
Error: This socket is closed.
at Socket._write (net.js:637:19)
at doWrite (_stream_writable.js:226:10)
at writeOrBuffer (_stream_writable.js:216:5)
at Socket.Writable.write (_stream_writable.js:183:11)
at Socket.write (net.js:615:40)
at Object.<anonymous> (e:\Projects\scaffold-angular\test.js:18:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
I've tried this with slimrb as well, same 'socket is closed' error.
The commands all work find when I manually enter it on the console (tried both MINGW32 and normal windows commandline).
$ sass
.asdfsadf
color: red
^Z
.asdfsadf {
color: red; }
My node is v0.10.28
edit: updated to v0.10.29, same issue :(
You can use the cross-spawn package as a drop-in replacement for child_process.spawn.

Oracle connectivity with NodeJS and ExpressJS

I am trying to connect oracle with NodeJS. Steps followed as below. Pre - requisites there is no client installed except NodeJS(0.10.25) and npm(1.3.24).
In my ExpressJS Project:
npm install db-oracle
There is no error found while installing.
In app.js
var oracle = require('db-oracle');
var connString = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxxx)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=xxxx)))";
var connectData = { "tns": connString, "user": "XPPS_OWNER", "password": "Ex3ec" };
In one of the endpoint i coded like this,
app.get('/oracleendpoint',function(req,res){
connectData.connect(function(error) {
if (error) {
return console.log("CONNECTION ERROR: " + error);
}
this.query().select('*').from('Users').execute(function(error, rows) {
if (error) {
return console.log('ERROR: ' + error);
}
console.log(rows.length + ' ROWS');
});
});
});
Expected output is to connect the DB.
FYI: DB Instance is running fine.
Query:
What is the DB Name?
It is showing an error which show below. what would be root cause for this?
module.js:340
throw err;
^
Error: Cannot find module './build/Release/oracle_bindings'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous>
(C:\xampp\htdocs\mytest\node_modules\db-oracle\db-oracle.js:18:15)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
Please let me know any missing or Installation required or any node modules required or code changes. I have Googled but in vain. Haven't found proper document for this error.
Oracle themselves have just released an Oracle driver for node.js: https://blogs.oracle.com/opal/entry/introducing_node_oracledb_a_node
Looks promising.
In your example, you use db-oracle module, I would recommend to use node-oracle module instead, as it is more popular/better maintained.
To connect to Oracle DB from Node, you have to follow the instructions on the page mentioned above.

Creating temporary view in couchdb using node-couchdb-api

I am trying to connect couchdb using node-couchdb-api at nodejs level as mentioned in the following link http://dominicbarnes.us/node-couchdb-api/.My couchdb version is 1.1.1 and nodejs version is 0.6.10.
For creating temporary view as mentioned in api http://dominicbarnes.us/node-couchdb-api/api/database/tempView.html I have written the following code.
var couchdb = require("couchdb-api");
var server = couchdb.srv(localhost, 5984, false, false);
var db = server.db("test");
var map = function (doc) {
emit(null, 1);
};
var reduce = "_sum";
var query = { include_docs: true };
db.tempView(map, reduce, query, function (err, response) {
console.log(response);
});
But i am facing the following problem.
C:\Program Files\nodejs\node_modules\couchdb-api>node server.js
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Cannot read property '0' of null
at C:\Program Files\nodejs\node_modules\couchdb-api\lib\util.js:24:39
at Array.map (native)
at Object.formatFunction (C:\Program Files\nodejs\node_modules\couchdb-api\lib\util.js:22:25)
at Object.tempView (C:\Program Files\nodejs\node_modules\couchdb-api\lib\database.js:285:28)
at Object.<anonymous> (C:\Program Files\nodejs\node_modules\couchdb-api\server.js:27:4)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)
please suggest me to resolve the issue.
Thanks in advance.
sorry about the problem you were experiencing. I'm the creator of that module, and I've just pushed version 1.1.2 up to NPM which addresses your problem. (and includes a unit test to make sure it doesn't happen again)
Just update to the latest version via npm update couchdb-api and you should be set to go. Let me know if you have further issues.

process.nextTick error in node.js?

I am getting process.nextTick error on this very basic example of node.js.
Can someone please figure out?
Is node not able to start listening on port 8000?
# cat nodejs.js
net = require("net");
s = net.createServer();
net.on('connection', function (c) {
c.end('hello');
});
s.listen(8000);
# node nodejs.js
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Object #<Object> has no method 'on'
at Object.<anonymous> (/home/ec2-user/praveen/nodejs.js:4:5)
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
at Array.0 (module.js:470:10)
at EventEmitter._tickCallback (node.js:192:40)
It's a typo in Ryan's slide! :-0
s/net.on/s.on/
It seems you're trying to capture an event on the library (net), but you should be looking at the connectionListener argument to createServer. Try this instead:
var net = require("net");
var server = net.createServer(function (c) {
c.end('Hello!'); // Implicitly fired on 'connection'
});
server.listen(8000);
For anyone else who might stumble here looking for why node pukes this error when they try to issue brunch watch --server, check and make sure you don't have any other servers running using the same port (i.e. in another shell).

Resources