[TW5] Requiring node.js modules

68 views
Skip to first unread message

Kurt Kincaid

unread,
May 7, 2015, 7:22:06 PM5/7/15
to tiddly...@googlegroups.com
I am working on an encryption project with TW where I need to leverage an additional node.js core module (crypto, in this case) and a non-core module (node-forge). I read the thread where Jeremy mentioned that the easiest way to include other node modules is to wrap them as a plugin. Make perfect sense, and I suspect works in almost all cases. In my case, though, I do not think this will work. First, with crypto, since it is a core module, I cannot easily wrap it as a TW plugin. Second, in the case of node-forge, it is actually comprised of numerous Javascript files, some of which are fairly large (~ 130K).

My question is this: is there another way to include additional node modules without wrapping them as a plugin? I do not want to modify boot.js since that will make upgrading problematic.

If anyone could point me in the right direction, I would really appreciate it.

Thanks!!

Kurt

Jeremy Ruston

unread,
May 14, 2015, 5:40:01 AM5/14/15
to TiddlyWikiDev, Kurt Kincaid
Hi Kurt

Apologies for the delayed response.

On Fri, May 8, 2015 at 12:22 AM, Kurt Kincaid <ku...@kurtkincaid.com> wrote:
I am working on an encryption project with TW where I need to leverage an additional node.js core module (crypto, in this case) and a non-core module (node-forge). I read the thread where Jeremy mentioned that the easiest way to include other node modules is to wrap them as a plugin. Make perfect sense, and I suspect works in almost all cases. In my case, though, I do not think this will work. First, with crypto, since it is a core module, I cannot easily wrap it as a TW plugin. Second, in the case of node-forge, it is actually comprised of numerous Javascript files, some of which are fairly large (~ 130K).

My question is this: is there another way to include additional node modules without wrapping them as a plugin? I do not want to modify boot.js since that will make upgrading problematic.

Under Node.js, if the target of a require() call doesn't exist as a tiddler, then the call is passed down to Node.js. So you should be able to just do `require("crypto")` to use the crypto library (as long as you don't have a tiddler called "crypto"). For the non-core module you'll need to use npm to install it but then you can use require in the same way.

Best wishes

Jeremy.

 

If anyone could point me in the right direction, I would really appreciate it.

Thanks!!

Kurt

--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikide...@googlegroups.com.
To post to this group, send email to tiddly...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywikidev.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywikidev/279bebc3-18be-4ce6-ab63-f6f6852e11f5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Jeremy Ruston
mailto:jeremy...@gmail.com
Reply all
Reply to author
Forward
0 new messages