porting a library to node.js

83 views
Skip to first unread message

Massimiliano Tomassoli

unread,
May 11, 2014, 8:21:54 AM5/11/14
to nod...@googlegroups.com
Hi everyone,
I'd like to port a Dart library to node.js (https://github.com/mtomassoli/golib) but I don't know much about node.js.
I have some questions:
  1. Do you already have goroutines and channels in node.js?
  2. Can I use yield?
  3. How can I add a function to the event loop? (I'll need to emulate Dart's completers)
  4. What's the structure of a node.js library/module? Any links?

Thanks.


Angel Java Lopez

unread,
May 11, 2014, 10:53:49 AM5/11/14
to nod...@googlegroups.com
Hi!

You again ;-) ;-) (after Scala, Clojure.. )

1) No goroutinges, but streams and events (stream2 is the "new" implementation, two years age). But maybe JavaScript generators? I'm not sure.

2) No yield, until new ecmascript 6, but some links
(v 0.11 not the stable 0.10.x)

3) setImmediate(myfn); or setTimeout(myfn, 0) (later is preferred, if your library should run in browsers too; not all the browsers implements setImmediate)

4) It's really simple. A complex number arithmetic library
The key part is the package.json file where you define the entry point, the dependencies, the scripts to run (what is "npm test"?), the dev dependencies. You can get an account on NPM, and publish your module

Sometimes, your main module.js is splitted, like in
but you can still tests the files 

notice the use of .npmignore to not publish samples files

Sometimes, your separated files should be arranged in one, to support browsers

It could be rearrange with automation commands in only one to be used in browser. In the above project, I did the work with a windows command, and using the trick of defining each submodule in a function

mysubmodule = (function() { 
...
   return ....
}

if (typeof module != 'undefined' && module.exports)
    module.exports = mysubmodule;

and concatenating all the files in order

But you can use browserfy by @substack 

Sure, there are more complete and better samples

You can read a lot of good code and module use/patterns at

Angel "Java" Lopez
@ajlopez




--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/fa584a27-76b5-49e8-a4b8-6ac86bdaaa95%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Massimiliano Tomassoli

unread,
May 11, 2014, 12:46:34 PM5/11/14
to nod...@googlegroups.com
Yep, it's me again :)

Thanks for the detailed answer!

Alexey Petrushin

unread,
May 12, 2014, 6:32:46 AM5/12/14
to nod...@googlegroups.com
1. No, but there are Fibers
2. Yes, with Fibers.

But you should know that this approach is considered as heresy by righteous node.js developers ;)

Alex Kocharin

unread,
May 12, 2014, 6:17:09 PM5/12/14
to nod...@googlegroups.com
 
> 2) No yield, until new ecmascript 6, but some links
 
Something like facebook/regenerator would run that on stable 0.10 quite happily.
 
 
11.05.2014, 18:54, "Angel Java Lopez" <ajlop...@gmail.com>:
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAMs%2BDqK9LZ0O31gZFDeX5SrYQ2%2Bi1iTOmT9YAN5Zgx253Gdx1g%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages