Background Process Mode
Thestart:bg script runs psys as a detached background process that continues running even after closing your terminal.
Build the production bundle
Build the application at least once before starting in background mode:This creates an optimized production build using
next build.Access the application
Open http://localhost:30999 in your browser.The app continues running in the background on port 30999.
Background Script Breakdown
Thestart:bg script uses several techniques to run as a background process:
| Component | Purpose |
|---|---|
nohup | Prevents the process from being terminated when the terminal closes |
next start | Starts the Next.js production server |
-p 30999 | Runs on port 30999 instead of the default 3000 |
> /dev/null | Redirects standard output to null (no terminal output) |
2>&1 | Redirects standard error to standard output (also suppressed) |
& | Runs the command in the background |
With this configuration, the server produces no terminal output. To monitor the application, access it through the web interface or check system logs.
When to Use Each Mode
Development Mode
Use
npm run dev when:- Developing new features
- Testing changes with hot reload
- Debugging issues
- Need detailed error messages
Production Mode
Use
npm start when:- Running in production
- Need optimized performance
- Want to test production build locally
- Terminal needs to stay open
Background Mode
Use
npm run start:bg when:- Running continuously in production
- Want to close the terminal
- Need a dedicated monitoring port
- Running as a system service
Never Use
Don’t use
npm run dev in production:- Slower performance
- Larger memory footprint
- Security implications
- Not optimized for production workloads
Stopping the Background Process
To stop a background process started withnpm run start:bg: