Node.js Compatibility with Bare
Bare offers seamless compatibility with Node.js counterparts. Most of the modules and APIs used by developers are covered and supported.
Currently supported modules
child_process
:bare-subprocess
(throughnpm:bare-node-child-process)
console
:bare-console
(throughnpm:bare-node-console)
events
:bare-events
(throughnpm:bare-node-events)
fs
:bare-fs
(throughnpm:bare-node-fs)
http
:bare-http1
(throughnpm:bare-node-http)
inspector
:bare-inspector
(throughnpm:bare-node-inspector)
os
:bare-os
(throughnpm:bare-node-os)
path
:bare-path
(throughnpm:bare-node-path)
process
:bare-process
(throughnpm:bare-node-process)
readline
:bare-readline
(throughnpm:bare-node-readline)
repl
:bare-repl
(throughnpm:bare-node-repl)
tty
:bare-tty
(throughnpm:bare-node-tty)
url
:bare-url
(throughnpm:bare-node-url)
Config for the Node.js stdlib
To get the full Node.js compatible layer that Bare currently supports add the following lines to the package.json file.
Example
Support for 'fs'
Simply add the following lines in the package.json file for using 'fs' in a Bare Application.
Firstly, install bare-fs
newer than ^2.1.5
. Then, alias fs
to the wrapper npm:bare-node-fs
.
The only thing the wrapper does is module.exports = require('bare-fs')
and at version *
, meaning the version that is specified is used.
Using the wrapper saves space as npm will only include bare-fs
once if something else installs it.
Using import maps
When writing a module that uses fs
the mapping can be specified directly in the module instead of relying on the compatible. This can be achieved using an 'import map'.
For example Localdrive uses fs
and to work in both Bare and Node.js it adds the following import map to the package.json file.
This way the module is in full control of exactly which version of fs
is bound to Bare.
This is the best option, as it provides the best of both worlds. Node.js compatibility, but with full control of the dependencies.
Last updated