Node.js Deployment
Deploy your React Just app using a Node.js environment.
Installation
Install the Node.js adapter package in your project:
$ npm install @react-just/node
$ pnpm add @react-just/node
$ bun add @react-just/node
Add the plugin in the Vite config file:
import node from "@react-just/node";
import react from "react-just/vite";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [react(), node()],
});
Building the App
Build the app with the vite build
command. For convenience, add the following script to your package.json
:
{
"scripts": {
"build": "vite build"
}
}
Then build the app with:
$ npm run build
$ pnpm build
$ bun run build
By default, the build will be placed in the dist
directory. You can change it with the build.outDir
Vite config option:
import node from "@react-just/node";
import react from "react-just/vite";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [react(), node()],
build: { outDir: "lib" },
});
The static
Folder
Static assets are emitted to the static
folder in the output directory. These can be served directly (e.g., from object storage like S3 behind a CDN).
Start the Server
Start a server using the react-just-node
command.
$ npx react-just-node
$ pnpm react-just-node
$ bun react-just-node
By default, this will:
- Serve the build in the
dist
directory. - Statically serve the files in the
dist/static
directory. - Listen on port
3000
, making your app available athttp://localhost:3000
.
Add a Script
For convenience, add a start
script to your package.json
:
{
"scripts": {
"start": "react-just-node"
}
}
Then start your app with:
$ npm run start
$ pnpm start
$ bun start
For details about the adapter and CLI options, see the Node.js adapter reference.