Hi, Will:
There are some significant differences between Node.js and MarkLogic as a
JavaScript runtime environment (even though both make use of v8).
First and foremost, Node.js emphasizes asynchronous IO. As a transactional
database, MarkLogic emphasizes synchronous IO. You can execute asynchronous
actions in MarkLogic (via the task server), but when you do an
xdmp.documentInsert(), the operation blocks until the operation succeeds or
fails.
Stepping back, the tier where you implement an action is not arbitrary. In the
database, it's best to write short actions (similar to stored procedure) for
query expansion, query composition, inbound or outbound data transformation,
and so on. The middle tier is great for information bus operations, business
logic, and so on.
With that perspective, the libraries that make sense to use as dependencies for
server-side JavaScript actions are those that finish synchronous actions
quickly.
For that reason, in the particular case, my guess would be that js-xlsx (the
core library wrapped by node-xlsx) might be a better fit for server-side
processing than node-xlsx (which adds asynchronous IO conveniences that would
not work in the server).
At present, you would need to either modify the mimetypes configuration to
identify *.js as an extension for server-side JavaScript (so the server knows
that it's not static JavaScript to send to the client) or rename the library
extension to sjs.
You could put the library in the modules database as described in:
http://docs.marklogic.com/guide/rest-dev/extensions#id_55309
Then, require the library in your transform or main module.
The speculations about package management for such dependencies is very
interesting.
By the way, the server can extract metadata from spreadsheets without
installing an external library:
http://docs.marklogic.com/guide/search-dev/binary-document-metadata#id_74790
Hoping that helps,
Erik Hennum
________________________________
From: [email protected]
[[email protected]] on behalf of Will Lawrence
[[email protected]]
Sent: Sunday, July 12, 2015 7:19 PM
To: [email protected]
Subject: [MarkLogic Dev General] Can node libraries be installed server-side?
I tried but couldn't find any examples or guidance for using node libraries
within .sjs files on the MarkLogic server. How could we use, for example, the
npm module 'node-xlsx' in a transform?
It would be great to be able to leverage the power of the npm and node
micro-library ecosystem within .sjs files.
Perhaps there could be an .npmrc file controlled via the MarkLogic admin to
specify if the server is allowed to talk to
registry.npmjs.com<http://registry.npmjs.com> or an enterprise npm registry or
non at all. Then, a REST API could be exposed to write dependencies to the
MarkLogic's package.json that would automatically do an 'npm install' so that
when an .sjs file is installed, it can execute the line:
```spreadsheetShredder = require('node-xlsx');
Regards,
Will
_______________________________________________
General mailing list
[email protected]
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general