Try โ€‚โ€‰HackMD
YAMLException: end of the stream or a document separator is expected at line 13, column 20: 3. and add scripts : ^

title: Set up concurrently for ReactJS and backend
tags: Web Dev

Set up concurrently for ReactJS and backend

  1. Root folder should install concurrently and nodemon in devDependencies

    โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹ npm install --save-dev nodemon concurrently
    
  2. Run in root folder termial npx create-react-app client (creat your frontend react app)

  3. and add scripts :

    โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹ {
    โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹     โ€clientโ€ : โ€npm start  -prefix clientโ€,
    โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹     โ€œdevโ€ : โ€concurrently \โ€npm run server\โ€ \โ€npm run client\โ€โ€
    โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹ }
    

    (If your frontend folder name is [client] )

    Copy:

    โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹ "scripts": {
    โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹     "start": "node server",
    โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹     "server": "nodemon server",
    โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹     "client": "npm start -prefix client",
    โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹     "dev": "concurrently \"npm run server\" \"npm run client\""
    โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹   },
    

    In package, json (root folderโ€™s)

  4. testing( npm run dev ) In root folder, it should be work

  5. delete โ€œREADEME.mdโ€ and โ€œ.gitignoreโ€

  6. in client folder, terminal โ€œrm -rf .gitโ€

    // Do or not do up to you (Just convient for dev to request,axios, cut some string)

  7. In client folder โ€œpakage.jsonโ€ add

    (If backend port number is [5000] )

    โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹ โ€œproxyโ€ : โ€œhttp://localhost:5000โ€
    โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹          โ€œhttp://127.0.0.1:5000โ€  (same)	
    

    Copy:

    โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹   "proxy":"http://localhost:5000โ€,
    

    or

    โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹   "proxy": "http://127.0.0.1:5000",
    

for setting pop browser, I already set environment variable to Microsoft edge, so no need to add.
( // "start": "BROWSER='Microsoft Edge' react-scripts start",
)