- 1 year ago
Mixing concurrently and cross-env in a package.json script
Yes, you can use concurrently
and cross-env
together in a package.json
script. Here's an example script:
json{
"scripts": {
"start": "concurrently \"cross-env NODE_ENV=development nodemon server.js\" \"cd client && npm start\""
}
}
In this example, we are using concurrently
to run two commands concurrently: cross-env NODE_ENV=development nodemon server.js
and cd client && npm start
.
The first command sets the NODE_ENV
environment variable to development
using cross-env
, and then runs nodemon
to watch for changes to server.js
and restart the server when necessary.
The second command changes the working directory to client
, and then runs npm start
to start the React development server.
By using concurrently
, both of these commands can run at the same time in separate console windows, which can be more convenient than having to manually run each command separately.
Note that in order to use cross-env
, you need to have it installed as a dev dependency in your project (npm install --save-dev cross-env
).