A boilerplate of an Express server that renders pages (made with React components) using NextJS.
I made this project for future personal use but if you want you can use it too. π
- express
- next: Render React components in server-side.
- react
- typescript: To ensure code type-safety.
- ts-node-dev: Run Typescript files on Node without manually compiling them before.
git clone https://github.com/iagobruno/nextjs-with-custom-server-boilerplate.git
cd nextjs-with-custom-server-boilerplate
yarn install
yarn run start:dev
: Start server in development mode on port 3000 using ts-node-dev. It will restart if you make changes to any file.- You can use
--api-only
argument to prevent starting nextjs.
- You can use
yarn run start:debug
: Same as the above command but optimized to be attached by VS Code debugger.yarn run build
: Compile server and client codes into a production optimized version.yarn run start
: Start server in production mode. Requires the "build" command to be executed first!
.
βββ .vscode
βββ client // Contains all client-side codes.
β βββ components // Folder with React components.
β βββ pages // Folder with Next's Page components.
β βββ next.config.js // Self explanatory.
β βββ tsconfig.json // TypeScript compiler options specific to client codes.
βββ common // Contain files that are used in many parts of the project.
βββ dist // Folder where compiled server code will be placed by the "build" script.
βββ public // Contains static files to be publicly served by Express.
βββ server
β βββ main.ts // Config express server.
β βββ next.ts // Init NextJS.
β βββ start.ts // Start express server.
βββ globals.d.ts
βββ tsconfig.json // Main Typescript compiler options
βββ package.json
βββ yarn.lock