My project is split into 2 folders
client and server
in the client folder the usual
react-create-app package.json
in sever folder
package.json with trace script
scripts: {
start: node app.js
server: nodemon app.js
}
how can I run the script through npm start to run both the backend and the frontend at the same time
client
-app.js
-package.json
server
-app.js
-package.json
I found a solution that you can start from the server folder as follows
dev: "concurently" npm run server "" npm run client "
but how to start if package.json is in different folders
you need to cd into your root directory or where both client and server folders are and npm install, npm init, git init, touch gitignore and add /node_modules
In your package.json in your root directory add this:
"client": "cd client && npm start",
"backend": "cd server && nodemon server.js",
"dev": "concurrently \"npm run backend\" \"npm run client\"",
In your server directory, npm install and touch gitignore /nodemodules
In your package.json add this:
"scripts": {
"start": "node server.js",
"server": "nodemon server.js"
},
In your client folder, npm install and touch gitignore /node_modules
In your package.json add this:
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}
Then you can always run your app and server by just cd into your main directory, and doing npm run dev.
Btw: Its hard to deploy servers to heroku when they are separated into a folder and they aren't in a root directory.