Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 592
El Dude Avatar asked Jun 26 '15 01:06

El Dude


People also ask

Can you use NPM packages without node?

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).

Can js run without NodeJS?

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.

Can I use require without node?

A module loader called RequireJS exists for in-browser use without the use of Node.


2 Answers

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.

like image 157
David Dao Avatar answered Sep 24 '22 17:09

David Dao


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() 
like image 40
Luís Brito Avatar answered Sep 24 '22 17:09

Luís Brito