npm Install different folders with one script - reactjs

I want to run one npm install on the project root to install both server and client packages.
My project structure is:
project
│ package.json
| node express files...
└───client
│ package.json
| react app files...
And also, create one script that runs npm run dev on the root folder and npm start on the client folder.
I tried to use concurrently, and it does work for running the apps, but for installing, I get a weird infinite loop that keeps installing in the root folder:
terminal screenshot
And I guess if concurrently is not globally installed, it wouldn't work anyway for the first installation.
package.json scripts in the root folder:
"scripts": {
"test": "jest",
"start": "node index.js",
"build": "cd client && npm run build",
"install-client": "cd client && npm install",
"heroku-postbuild": "npm run install-client && npm run build",
"dev-client": "cd client && npm start",
"dev": "nodemon index.js",
"install": "concurrently \"npm install\" \"npm run install-client\"",
"dev-both": "concurrently \"npm run dev\" \"npm run client-dev\""
},
Any ideas how for a fix or an alternative way to do this?

To avoid infinite loop, try this :
"both-install": "concurrently \"npm install\" \"npm run install-client\"",

to install client try this:
"install-client": "cd ../client && npm install",

Related

"concurrently" not working for parent directory client reactjs server

"concurrently" not working for parent directory client reactjs server.
concurrently commands are:
"scripts": {
"client": "cd ../ --prefix client && npm run start",
"server": "nodemon index.js",
"dev" : "concurrently \"npm run client\" \"npm run server\" "
}
Directory structure is
client
server
With Your folder structure Try this settings:
"scripts": {
"start": "node server/index.js",
"server": "nodemon server/index.js",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\"",
},
And hit npm run dev It should work fine ;-) Remember to install concurrently correct.

I have downloaded the ethereum blockchain project build in react,solidity,truffle

Now It doesn't run on my ubuntu machine. When I run the npm start command it says missing script start. Is there any method to run the downloaded project?
In your package.json file, check scripts property:
"scripts": {
"clean": "rimraf build/*",
"copy-assets": "ts-node src/tools/copyAssets",
"tsc": " tsc",
"build": "npm-run-all clean tsc copy-assets",
"dev": "nodemon --watch src -e ts,ejs,css --exec npm run dev:start",
"dev:start": "npm-run-all build start",
},
Looks like start script does not exist. Instead run the appropriate one from the scripts section.

React build with env file from a command line

Is there any way to create React App build from a command like? So far I have in the shell script:
npm install;
npm run-script build:test;
where build:test is
bash -ac '. .env.test; react-scripts build'
but that will refer to build:test script from package.json but when I want to use specific .env file in the shell script (without editing or adding anything to package.json) as follow
npm run .env.my_box react-scripts build;
that will not execute build for .env.my_box
What I have set incorrectly?
you should try this library https://github.com/toddbluhm/env-cmd
Update your package.json
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"build:stage": "env-cmd -f ./.env.stage npm run-script build"
}
then npm run build:stage
You could do something like this:
on package.json
"scripts": {
"server": "cd server && npm start",
"client": "cd client && npm start",
"server-dep": "cd server && npm install",
"client-dep": "cd client && npm install",
"install-dep": "npm install && concurrently \"npm run server-dep\" \"npm run client-dep\"",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"test": "echo \"Error: no test specified\" && exit 1"
},
then npm run start for example, this is monorepo so we run server and frontend with one command

call npm script in package.json through bamboo build to trigger build

I have my package.json as below. I would like to trigger a bamboo build through npm scripts which should trigger npm install and then it should trigger npm run bamboo.
I am trying to make the build fail if my testcases fail.kindly help in how to configure in bamboo to achieve the same
"scripts": {
"dev": "webpack",
"prod": "webpack -p",
"start": "webpack-dev-server --open",
"build": "npm run clean-dist && npm run dev && npm run start",
"pbuild": "npm run clean-dist && npm run prod && npm run start",
"clean-dist": "rimraf ./dist && mkdir dist",
"lint": "esw webpack.config.js app",
"lint:watch": "npm run lint -- --watch",
"test": "karma start --reporters html",
"pro": "protractor protractor.config.js",
"bamboo": "npm run clean-dist && npm run dev && npm run test"
}
In bamboo plan configuration:
1. Add new task
2. Select 'npm' type
3. Select Node.js executable - version of your nodeJs, installed on the server
4. Command: run test
This will run your 'test' script from package json

React scripts fails while i run concurrently with nodemon

When i run npm start the above error occurs.
my script in package.json:
"start": "concurrently \"nodemon server\" \"react-scripts start\"",
Any help will be great !
One of the ways you can do is (You can amend it accordingly) :
"server": "nodemon index.js",
"react": "react-scripts start"
"dev": "concurrently \"npm run server \" \"npm run react\" "
And then do npm run dev
You can read more about concurrently here

Resources