Setting up React
Installation
Include html file with a root div
Add these script
react-scripts creates the root html page
Create-react-app
Check process.env.NODE_ENV
for the current environment either "production" when built or "development"
To set all imports to be absolute "components/CTA.js" instead of "../components/CTA.js", add the following file to the root(package.json level) dir
jsconfig.json
Setup With Node
In backend/bin/www
, change the default port number to 3001
In client/package.json
add "proxy": "http://localhost:3001"
to the json
Now in the main folder fullstack_app:
In package.json
, add "start": "concurrently \"cd backend && npm run start\" \"cd client && yarn start\""
under scripts
Now just npm run start
in the main folder
Docker
Use docker-compose to get two containers up, use "proxy": "http://[service-name]:[port-number]"
instead
Gotchas
Express generator comes with express.json bodyparsering which is a much less lenient form of post request processing then the bodyparser package(must specify application/json header)
Nodemon needs to be added
React-generator uses yarn and has a yarn.lock, it became a problem
Last updated