nodejs-rdkit

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.use(bodyParser());

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>' +
	      '</form>';
  var msg = mw + ' mw '
  res.send( html  );
 });


app.post('/', 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.
https://github.com/iwatobipen/nodetest

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.


					
広告

コメントを残す

以下に詳細を記入するか、アイコンをクリックしてログインしてください。

WordPress.com ロゴ

WordPress.com アカウントを使ってコメントしています。 ログアウト / 変更 )

Twitter 画像

Twitter アカウントを使ってコメントしています。 ログアウト / 変更 )

Facebook の写真

Facebook アカウントを使ってコメントしています。 ログアウト / 変更 )

Google+ フォト

Google+ アカウントを使ってコメントしています。 ログアウト / 変更 )

%s と連携中