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
Whether or not the library will work without Node will depend on the library. If it presents itself as a Node module, then you'll probably have to modify it (or find a compatible module loader for browser-side JS).
No. Why would you need that? hm, you need a JS engine - such as V8 which is used by node - and at least some APIs / standard libraries which allow you to read / write / interact with the command line.
A module loader called RequireJS exists for in-browser use without the use of Node.
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.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With