Saturday 22 April 2017

Include static data files in an NPM package, use them in a portable way

I want to publish an NPM package that contains a large-ish amount of static data files. There could be 1000 files, containing 1 KB of data each, yielding 1 MB or so of data. It is important that that the environment only load files as they are required by the code (which is determined at runtime).

I want the package to be usable from both server and client, and using any CommonJS implementation.

How can I do this in a user-friendly way?

Although less important, is there a way to structure the code so that a module system is not required? (e.g. so the code and data can be used through HTML tags).

While specific environments have ways to require static data files, those are different and environment-dependent. Different environments also have different ways of accessing the files (in a web browser, you'd send a GET request, while in a server environment you'd read the file from the file system).



via GregRos

No comments:

Post a Comment