ts-odd
ts-odd copied to clipboard
NodeJS support
We have limited support for NodeJS right now.
Some areas still expect the browser environment (eg. usage of fetch), such as the DNS module.
You can use file systems in node today by using the dependency injection system in webnative:
import "webnative/setup/node.js"
This will switch out the browser dependencies with the NodeJS equivalents. See tests for examples.
You can also do switch out individual pieces:
import * as webnativeStorage from "webnative/storage/implementation.js"
webnativeStorage.set({
getItem: inMemoryStorage.getItem,
setItem: inMemoryStorage.setItem,
removeItem: inMemoryStorage.removeItem,
clear: inMemoryStorage.clear,
})
Ideally the node implementations should be loaded automatically when webnative is used in NodeJS. Although, I don't know fully know the implications regarding bundlers. We'll most likely switch to Deno and that will have some impact as well: https://github.com/denoland/dnt#built-in-shims
It's technically possible to have it work in NodeJS now. You will have to write a few components to get there, but it's possible.