All Projects → IKatsuba → rxnode

IKatsuba / rxnode

Licence: other
Rxnode - a small and fast wrapper around the nodejs API using RxJS.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to rxnode

Electron Filesystem
FileSystem for windows
Stars: ✭ 409 (+1604.17%)
Mutual labels:  filesystem, fs
Fast Glob
🚀 It's a very fast and efficient glob library for Node.js
Stars: ✭ 1,150 (+4691.67%)
Mutual labels:  filesystem, fs
Fdir
⚡ The fastest directory crawler & globbing library for NodeJS. Crawls 1m files in < 1s
Stars: ✭ 777 (+3137.5%)
Mutual labels:  filesystem, fs
Tfs
Mirror of https://gitlab.redox-os.org/redox-os/tfs
Stars: ✭ 2,890 (+11941.67%)
Mutual labels:  filesystem, fs
Nohost
A web server in your web browser
Stars: ✭ 164 (+583.33%)
Mutual labels:  filesystem, fs
Chonky
😸 A File Browser component for React.
Stars: ✭ 313 (+1204.17%)
Mutual labels:  filesystem, fs
Memfs
In-memory filesystem with Node's API
Stars: ✭ 854 (+3458.33%)
Mutual labels:  filesystem, fs
korefile
File System API for Local/GitHub.
Stars: ✭ 29 (+20.83%)
Mutual labels:  filesystem, fs
Litfs
A FUSE file system in Go extended with persistent file storage
Stars: ✭ 116 (+383.33%)
Mutual labels:  filesystem, fs
Flint
Fast and configurable filesystem (file and directory names) linter
Stars: ✭ 115 (+379.17%)
Mutual labels:  filesystem, fs
mongoose-gridfs
mongoose gridfs on top of new gridfs api
Stars: ✭ 79 (+229.17%)
Mutual labels:  filesystem, fs
dropbox-fs
📦 Node FS wrapper for Dropbox
Stars: ✭ 35 (+45.83%)
Mutual labels:  filesystem, fs
fs.c
File system API much like Node's fs module (synchronous)
Stars: ✭ 65 (+170.83%)
Mutual labels:  filesystem, fs
Filer
Node-like file system for browsers
Stars: ✭ 389 (+1520.83%)
Mutual labels:  filesystem, fs
gof
Yet another simple Go filesystem wrapper
Stars: ✭ 13 (-45.83%)
Mutual labels:  filesystem, fs
Node Ntfs
Windows NT File System (NTFS) file system driver
Stars: ✭ 18 (-25%)
Mutual labels:  filesystem, fs
SimpleOS
Operating System Coded in Assembly and C
Stars: ✭ 72 (+200%)
Mutual labels:  filesystem, fs
watcher
The file system watcher that strives for perfection, with no native dependencies and optional rename detection support.
Stars: ✭ 37 (+54.17%)
Mutual labels:  filesystem, fs
Zbox
Zero-details, privacy-focused in-app file system.
Stars: ✭ 1,185 (+4837.5%)
Mutual labels:  filesystem, fs
Draxt
draxt.js – NodeList/jQuery-like package for File System (node.js)
Stars: ✭ 192 (+700%)
Mutual labels:  filesystem, fs

Rxnode

Rxnode — reactive nodejs API

At the beginning of 2020, my career as a frontend developer turned in an unexpected direction for me. I haven't written a single Angular component in a year. I Replaced Angular with server code and code for the CLI. It was a new and interesting experience for me, but it wasn't easy to solve my usual tasks without RxJS.

Let's look at a simple example of reading and writing a file using the native features of nodejs

import { readFile, writeFile } from 'fs';

readFile('src/some-file.js', (error, data) => {
  if (error) {
    console.error(error);
    return;
  }

  writeFile('src/some-file.js', data, (error) => {
    if (error) {
      console.error(error);
      return;
    }

    console.log('Success!');
  });
});

Code with callbacks after Angular seems complicated. First, I translated callbacks to promises.

import * as fs from 'fs';
import { promisify } from 'util';

const readFile = promisify(fs.readFile);
const writeFile = promisify(fs.writeFile);

readFile('src/some-file.js')
  .then((data) => writeFile('src/some-file.js', data))
  .then(() => {
    console.log('Success!');
  })
  .cacth(console.error);

I was OK with this solution until I needed to implement several tasks' competitive execution with a limit. RxJS has such an opportunity out of the box. Why would I invent my own algorithm on promises?

The promisify function is replaced by the bindNodeCallback function, which RxJS itself supplies.

import * as fs from 'fs';
import { bindNodeCallback, Observable } from 'rxjs';
import { mergeMap, switchMap } from 'rxjs/operators';

const readFile = bindNodeCallback(fs.readFile);
const writeFile = bindNodeCallback(fs.writeFile);

let files: Observable<string>;
const LIMIT = 2;

files
  .pipe(
    mergeMap(
      (file) => someProcessWithFiles(file),
      LIMIT
  )
  .subscribe({
    complete() {
      console.log('Complete!');
    },
  });

It quickly became apparent that you need to import and wrap the API in each file or move it to the library at the project level. And when there was more than one such project, I decided to put my developments in separate packages with the @rxnode scopes and published the GitHub code.

The project is NX Workspace. Each core package from nodejs corresponds to one library in a scope. If you want to use the fs package, you import functions with the same names from the@rxnode/fs packages.

import { readFile, writeFile } from '@rxnode/fs';
import { switchMap } from 'rxjs/operators';

readFile('src/some-file.js')
  .pipe(switchMap((data) => writeFile('src/some-file.js', data)))
  .subscribe({
    complete() {
      console.log('Complete!');
    },
  });

This is how you can start a simple server.

import { createServer } from '@rxnode/http';

const server = createServer();

server.subscribe(([req, res]) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('okay');
});

server.listen(8080).subscribe();

Currently, Rxnode contains only 4 packages out of 20 planned. An up-to-date list can be found in the documentation. We will be glad to receive any help in project development! We need your ideas and your hands!

About logo

The Rxnode logo features an axolotl. And this is the merit of my wife, for which many thanks to her!

While working on the library, she looked at the RxJS logo and asked me, "Is this an axolotl?" When I replied negatively, she suggested depicting the axolotl on the Rxnode logo in Node.js shades. So I did!

{% embed url="https://medium.com/rxnode/rxnode-reactive-nodejs-api-f32c8e02e295" %}

Packages

  • child_process
  • cluster
  • crypto
  • dns
  • events
  • fs
  • http
  • http2
  • https
  • inspector
  • net
  • process
  • readline
  • repl
  • stream
  • tls
  • tty
  • dgram
  • util
  • worker_threads

We are supported by

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].