A very lightweight boilerplate, for creating react apps, with express as the back-end. This project is inspired by the food lookup demo.
When the project is started with npm start, two processes are started simultaneously.
One is for the client, and is what the user will connect to, through the browser.
And is running on localhost:3000
The other is the server, that is responsible for api requests. And is running on localhost:3001
A more detailed explanation of this, can be found here.
To download and install this boilerplate, clone the repository, and install the node dependencies.
# Clone the project
$ git clone https://github.com/viktorstrate/create-react-express-app.git my-app
# Move to project
$ cd my-app
# Install dependencies, for both the server and the client
$ npm install && cd client && npm install
# Make sure you are in the project root
$ cd ..
# Start the server for development
$ npm startNow setup some enviroment variables, by copying .env.example to .env.
And edit the new file, to match your environment.
Before starting the server make sure you have a running MongoDB server, follow the MongoDB installation guide.
You can change the address to something other than
localhost, in the.envfile.
The following, explains what the different parts of the project does.
The client folder is a slightly modified version of create-react-app,
and contains the code that will be sent to the browser.
The server folder, contains the all logic that will run on the server.
server The root of the server logic
├─ api/ Where all the express routes are stored
├─── comments.js An example route
├─ models/ Models for the database
├─── Comment.js An example model
├─ mongoose.js Initial setup for the database
├─ server.js Entry point for server
To run in production, the project needs to be built first.
# Build the server and client
$ npm run build
# Serve the site
$ npm run serve