El Dude
El Dude

Reputation: 5618

Nodejs library without nodejs

How can I integrate a nodejs library into my non nodejs project? I am particularly needing this library: https://github.com/greenify/biojs-io-blast

Upvotes: 29

Views: 4626

Answers (5)

Luís Brito
Luís Brito

Reputation: 1772

Yes, you can do it using a Publisher/Subscribe pattern and a Queue library, such as RabbitMQ.

In the example below, the author is communicating a python script with a NodeJS one, using the RabbitMQ clients for each platform.

https://github.com/osharim/Communicate-Python-with-NodeJS-through-RabbitMQ

The code for sending from NodeJS:

var amqp       = require('amqp');
var amqp_hacks = require('./amqp-hacks');

var connection = amqp.createConnection({ host: "localhost", port: 5672 });

connection.on('ready', function(){
    connection.publish('task_queue', 'Hello World!');
    console.log(" [x] Sent from nodeJS 'Hello World!'");

    amqp_hacks.safeEndConnection(connection);
});

Then, receiving in python:

#!/usr/bin/env python
import pika
import time

connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()

channel.queue_declare(queue='task_queue', durable=True)


#our callback
def suscriber(ch,method , properties , body):
    print "[Y] received %r " % (body,)
    time.sleep( body.count('.') )
    print " [x] Done"
    ch.basic_ack(delivery_tag = method.delivery_tag)



channel.basic_qos(prefetch_count=1)
channel.basic_consume(suscriber, queue = 'task_queue')

print ' [*] Waiting for messages from Python. To exit press CTRL+C'
channel.start_consuming()

Upvotes: 1

Ningappa
Ningappa

Reputation: 1329

The node_module which provided is kind of xml parser. You can't add nodejs library (node_module) to non nodejs programs. You can get xml parser for Blast depending on kind of programming language you are using.

For example : For PHP phpBlastXmlParser and For java this might helpfull

Upvotes: 0

xdeepakv
xdeepakv

Reputation: 8135

This is the more common use case. Some of the node.js libraby, i like them too much i want to use it everywhere. But this library, what i see uses core modules of node.js like fs. I dont think you can use it without node dependency || node binary. But as Code Uniquely or others folks says, if you are using webpack as a build/dev. You can try, browserify or BioJS

Upvotes: 0

Arezki Lebdiri
Arezki Lebdiri

Reputation: 39

to integrate any node library you use the package manager NPM https://www.npmjs.com/ so to integrate your library do as follow

  1. open terminal
  2. cd path/to/your/project_dir
  3. type this line

    npm install biojs-io-blast

Upvotes: 0

David Dao
David Dao

Reputation: 2531

BioJS uses Browserify CDN to automatically generate a single JS file for usage. Either include

<script src="http://wzrd.in/bundle/biojs-io-blast@latest"></script>

in your html or download the JS file via this link.

We also have a live JS Bin example here.

Upvotes: 26

Related Questions