I often use flask for developing some web services.
Because it’s very easy and powerful tool and python library.
There are lot’s of extensions.

Yesterday, @kzfm san gave me useful information for developing web services via node-js.
I haven’t used node-js before, but I tried it.

Node-js is very major tools and also it can install many libraries using package management system ‘npm’.
RDKitjs can also be installed using npm.
So, I make sample using node-js.
First I set up my developing environment.

$brew install node
$npm install express -g
$npm install rdkit -g
$npm install express-generator -g
$mkdir nodetest
$cd nodetest && express myapp

   create : myapp
   create : myapp/package.json
   create : myapp/app.js
   create : myapp/public
   create : myapp/public/javascripts
   create : myapp/public/images
   create : myapp/routes
   create : myapp/routes/index.js
   create : myapp/routes/users.js
   create : myapp/public/stylesheets
   create : myapp/public/stylesheets/style.css
   create : myapp/views
   create : myapp/views/index.jade
   create : myapp/views/layout.jade
   create : myapp/views/error.jade
   create : myapp/bin
   create : myapp/bin/www
$cd  myapp
$npm install 

Then write app.js.

var express=require( 'express'  );
var RDKit=require( 'rdkit'  ); 
var bodyParser = require( 'body-parser' );
var app = express();


app.get('/', function(req, res){
  var html = '<form action="/" method="post">' +
	      'Enter smiles:' +
	      '<br>' +
             '<input type="text" name="smi" placeholder="smi" />' +
	      '<br>' +
	      '<button type="submit">Submit</button>' +
  var msg = mw + ' mw '
  res.send( html  );
 });'/', function(req, res){
  var smiles = req.body.smi;
  var mol = RDKit.Molecule.fromSmiles( smiles );
  var molwt = mol.getMW();
  var mol2d = mol.Drawing2D();
  var remol = mol2d.replace( /svg:/g, ''  );
  res.send( "molwt is:"+molwt+"<br><br>"+"smiles is:"+ smiles+"<br><br>"+remol+'<br>'+'<a href="/">back</a>' );

var server=app.listen(3000, function(){
    var host = server.address().address;
    var port = server.address().port;

    console.log('Example app listeing at http://%s:%s', host, port);

The way to write app.js seems to like flask.
It’s very useful because I can make chemoinfor app using only javascript ! ;-) Wow Wow.
It’s ready to go.
Run app, and access localhost:3000.

$node app.js #server will start....

You’ll see smiles parser…
upload source code to repo.

Screen Shot 2015-05-31 at 9.51.03 AM

Screen Shot 2015-05-31 at 10.02.11 AM

I’ll read documents about nodejs and express later.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.