Running npm concurrently - node.js

I have been referencing this post: How can I run multiple npm scripts in parallel?
However, neither of my apps launch with npm run dev. Both apps exit with code 1.
My package.json:
"scripts": {
"start": "ng serve",
"start:lt": "ng serve --configuration=lt",
"dev": "concurrently --kill-others \"npm start\" \"npm start:lt\""
}
And yes, I have concurrently installed.

you can use https://www.npmjs.com/package/foreman module to start app.
first, you need Procfile with commands, you plan to execute in parallel
start: ng serve
start_lt: ng serve --configuration=lt
second, add it to package.json
"scripts": {
"start":"nf start"
}
third - define PORT variable in .env file
PORT=4201
and, finaly, you can start your applicaiton by npm start - it will start foreman executable, that starts both start and start_lt components in parallel

Related

npm start json-server in background

I'm trying to have my npm start script run json-server in the background in parallel to then running react-scripts to start UI. How would I go about doing this? I've tried various things with single & and prestart, etc but everything results in json-server starting to watch my db file but then react-scripts doesn't run.
The main 2 which I thought should do the trick are below, but neither work.
"scripts": {
"prestart" : "json-server --watch ../sample-db.json --port 3010 --delay 800&",
"start": "set HTTPS=true&&react-scripts start",
and
"scripts": {
"start": "json-server --watch ../sample-db.json --port 3010 --delay 800&set HTTPS=true&&react-scripts start",
Not quite a duplicate, but as indicated by #Max this has a few options:
How can I run multiple npm scripts in parallel?
So here's one way:
"scripts": {
"start": "set HTTPS=true&&react-scripts start",
"mockserver": "json-server --watch ../sample-db.json --port 3010 --delay 800",
"startdev": "concurrently --kill-others \"npm start\" \"npm run mockserver\"",
}
And I see that on windows I need to use "start" which was why single ampersand wasn't working.

Start node server without as the application starts

I wish to address an issue that to start the route server, we need to run the command node routes.js to start the server. Is there any way to automatically start it as we start the application.
I am using expo for my react native application.
You can use concurrently installing the NPM (https://www.npmjs.com/package/concurrently) module as follow:
npm install concurrently --save
You can then edit your package.json:
"start": "concurrently \"command1 arg\" \"command2 arg\""
Example:
"start": "concurrently \"npm run server\" \"react-scripts start\""

npm: missing start script even though start is defined in the package.json file

I have start defined in my scripts on pakcage.json but npm still gives me the start not found error
"scripts": {
"start": "node server.js",
"server":"nodemon server",
"client":"npm start --prefix client",
"dev":"concurrently \"npm run server\" \"npm run client\""
},
This is for Node version 10.16.0 on Windows 10
Basically, you don't need a start script. In your package.json file,
...
"main": "server.js",
...
and in the terminal go to your project directory and type
nodemon
This will start your app upon your configurations!
That should help!

Attempting to deploy my app (Node, React, Socketio) to Heroku gives me "sh: 1: react-scripts: Permission denied"

So I am trying to make my first react app. I have it working just fine locally. The problem is that I cannot upload my project to Heroku.
This is my app setup:
my file arrangement. I built this starting with a create-react-app, wrapped that entire thing in a "client" folder, and created a normal node server arrangement outside. I haven't touched my react app's package.json" except to add a socketio dependency, other than that it is exactly what create-react-app spits out.
I get this error on console when attempting to upload:
"sh: 1: react-scripts: Permission denied"
I have gone through https://devcenter.heroku.com/articles/nodejs-support, but to no avail.
This is my "outside" package.json scripts and dependencies
"scripts": {
"client": "npm start --prefix client",
"server": "node server.js",
"start": "concurrently \"npm run server\" \"npm run client\"",
"heroku-postbuild": "cd client && npm run build"
},
"dependencies": {
"concurrently": "^4.0.1",
"express": "^4.16.4"
"socket.io": "^2.1.1"
}
UPDATE:
I've not gotten my application to work yet HOWEVER I finally found something interesting.
This: https://github.com/mars/heroku-cra-node
Looks like a barebones application I can essentially my stuff to, and have it work on Heroku. I've not added my code yet, I'll report back.
UPDATE:
Yep, seems to get past this permission BS. Now I just have to deal with getting socket.io client to connect... -_-
Change your script to this:
"scripts": {
"start": "node index.js",
"server": "nodemon index.js",
"client": "npm run start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"heroku-postbuild": "NPM_PRODUCTION=false npm install --prefix client && npm run build --prefix client",
},
npm run dev will start your server and client in development mode...
You can also install nodemon to make your life easier...

Concurrently does not modify NODE_ENV variable

So I'm working on a project using webpack and wanted to create a script on my package.json to run both dev and production mode from there. I'm a windows user and always use Concurrently to run multiple terminal tasks at the same time.
I set my package.json scripts like this:
"scripts": {
"start": "concurrently \"set NODE_ENV=\" \"webpack --watch\"",
"build": "concurrently \"set NODE_ENV=production\" \"webpack\""
},
The output of this in the terminal is:
set NODE_ENV= exited with code 0
Webpack is watching the files…
...
So basically webpack is working properly, but the variable is not being created/deleted. Both commands are failing.
If I run directly
set NODE_ENV=production
it works, so I'm a bit confused...
Any ideas?
Thanks a lot!
Change:
"start": "concurrently \"set NODE_ENV=\" \"webpack --watch\"",
"build": "concurrently \"set NODE_ENV=production\" \"webpack\""
to:
"start": "NODE_ENV= webpack --watch",
"build": "NODE_ENV=production webpack"
You cannot change the environment in one process and expect it to be changed in another started in parallel. You can only change the env of child processes and only on their startup. Child process always inherits the environment from the parent.
If the above doesn't work on Windows then use cross-env:
npm install --save-dev cross-env
and in package.json use:
"start": "cross-env NODE_ENV= webpack --watch",
"build": "cross-env NODE_ENV=production webpack"

Resources