// next.config.mjs located in the same directory as package.json
// *** START: Export a DEFAULT object, i.e nextConfig
const nextConfig = {}
// Produce standalone output
// ---------------------------------
// "next start" doesn't generate standalone output.
// Generate standalone output if BUILD_STANDALONE=true.
nextConfig.output = process.env.BUILD_STANDALONE === "true" ? "standalone" : undefined;
// *** END: Export
export default nextConfig;
export BUILD_STANDALONE=true
npm run build
#\cp -a data .next/standalone/ # For other file. e.g. myDb.sqlite
\cp -a public .next/standalone/
\cp -a .next/static .next/standalone/.next/
nextjs_port=4666
export PORT=${nextjs_port}
node .next/standalone/server.js
nextjs_app_name="openwritings.net"
nextjs_port=4666
# Remove entry if it already exists.
pm2 stop ${nextjs_app_name} || true
pm2 delete ${nextjs_app_name} || true
# Run & deploy using pm2
export PORT=${nextjs_port}
pm2 start node --name ${nextjs_app_name} -- .next/standalone/server.js
# Save it so after computer reboot, it will automatically run.
pm2 save
./standalone/
directory.For all your file paths, use relative path to the ROOT directory of your Next.js app.(<Next_ROOT_DIR>/package.json
)
./standalone/
directory becomes the <Next_ROOT_DIR>
directory.
Therefore, copy your files under ./standalone/
directory.
Example: my ./data/
is copied to ./standalone/
data/
├── _empty_db.txt
├── rampricesdeal.db
└── _readme.sh
package.json
#...
.next/standalone/data
├── _empty_db.txt
├── rampricesdeal.db
└── _readme.sh