Skip to content

irekrog/use-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

use-node

Nagranie.z.ekranu.2023-03-13.o.23.10.10.mov

useNode React server hook

This is a hook working with React Server Component (RSC) and Next.js with App Router.

Getting Started

npm install use-node

or

yarn add use-node

or

pnpm add use-node

Usage

import { useNode } from "use-node";
import { ClientComponent } from "./ClientComponent";

export default async function App() {
  const process = await useNode("node:process");
  console.log("env", process.env.NODE_ENV); // server log

  // pass this to the Client Component
  return <ClientComponent data={process.env.NODE_ENV} />;
}

Docs

useNode

const data = await useNode(module: Modules)

Possible modules

type Modules =
  | "node:async_hooks"
  | "node:buffer"
  | "node:child_process"
  | "node:cluster"
  | "node:console"
  | "node:constants"
  | "node:dgram"
  | "node:diagnostics_channel"
  | "node:dns"
  | "node:dns/promises"
  | "node:fs"
  | "node:fs/promises"
  | "node:http"
  | "node:http2"
  | "node:https"
  | "node:inspector"
  | "node:net"
  | "node:os"
  | "node:path"
  | "node:perf_hooks"
  | "node:process"
  | "node:querystring"
  | "node:readline"
  | "node:repl"
  | "node:stream/promises"
  | "node:stream/web"
  | "node:string_decoder"
  | "node:timers"
  | "node:timers/promises"
  | "node:tls"
  | "node:trace_events"
  | "node:tty"
  | "node:url"
  | "node:util"
  | "node:v8"
  | "node:vm"
  | "node:wasi"
  | "node:worker_threads"
  | "node:zlib";

Example

https://github.com/irekrog/rsc-server-data-example/blob/master/src/app/use-node/page.tsx

https://rsc-server-data-example.vercel.app/use-node