This week I gave a try at creating my first npm package, bringing a modest contribution to that wonderful technology.
I'm not going to write yet another tutorial about how to publish your own npm package, you should be able to find plenty of resources on the web. Here a pretty neat and concise tutorial I stumble across.
Basically creating an npm package consists of creating a repository on github which include a specific description file package.json, then register that package under a unique name so other programmers will be able to install it easily by typing npm install my-package-name and start using it in their application.
What I liked about the tutorial I pointed out above is that it describes how to create and register your package, but also how to write a test for it using mocha, a test framework and chai, an assertion library.
In the case of View & Data API, any test would need to call a REST webservice, hence it needs to be asynchronous. I had to tweak a little the approach exposed in the post in order to achieve asynchronous tests.
At the moment this version of the package is quite minimalistic but it already allows you to achieve the basic complete workflow from your node application:
- Generate authetication tokens
- File upload, including large uploads using the resumable API
- Registration (ie. triggering translation of your file)
- And monitoring the translation of your model
In the future, I'm planning to keep supporting and enhance this package to maintain it on the edge of what is doable with View & Data API.
The best example of use is probably the tests I wrote, so here they are. Remember, this is a node.js server-side library, so it doesn't do viewing.
You are able to install it using npm install view-and-data command.
Check view-and-data-npm on github for more details.