require module


How can I require module from projections?

As in require an external library?

Yes! how do i require external library?

I have defined library for constructor functions (Money, Quantity, Price
etc.) and I want use them in my projections.

We have discussed this internally previously what is the best way.

IIRC it can be done as of now (or with a very small change) if you
distribute the js file to each of the servers (we have some files we
do this with). However we have discussed that this is perhaps not a
good way of doing things and it may be better with a stream.

I don't remember if its immediately possible or if it needs a small
change on our part to do the file based one. I will find out for you.



On this note, it’d be quite nice if you could just npm and package.json to solve this problem :slight_smile:


If it happens you have multiple different versions of the same module in a cluster you can break projection idempotent behavior. If the same projection produces different output on different nodes it can break projections in case of recovery (network/hardware/master shift).


The same could be said of just copying files around though, at least with a manifest you could shrinkwrap and force versioning

Thats why we are looking at doing it with streams :slight_smile:

Still think it’d be quite nice to be able to leverage all those wonderful modules without having to cut and paste JS everywhere, is there a way this could be compatible with your plans?

We were thinking it would be relatively easy to write an adapter that
put a module into a stream for you