AWS Beanstalk Node js deployment issue - node.js

Hi I am trying to deploy node js app on AWS Elastic Beanstalk. However I am not able to deploy the same. Every-time the build fails.
Getting below error:
During an aborted deployment, some instances may have deployed the new application version. To ensure all instances are running the same version, re-deploy the appropriate application version.
Sharing part of package.json for reference.
"scripts": {
"start": "node server.js",
"server": "nodemon server",
"client": "npm start --prefix client",
"debug": "ndb server.js",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"test": "mocha --recursive --timeout 20000 --exit",
"heroku-postbuild": "cd client && NPM_CONFIG_PRODUCTION=false npm install && npm run build"
},

Related

npm install command keeps repeating while deploying to heroku

I have a project that I want to deploy to heroku. The folder structure is as follows,
Root > client, server
these folders client and server has their own package.json file, so I wrote an installation command like "install" : "npm install --prefix client && npm install --prefix server".
but when I try to deploy it to heroku the build process keeps running npm install in the cli.
heroku cli while building
Root package.json
"scripts": {
"install": "npm install npm install --prefix server && npm install --prefix client",
"build": "npm run build --prefix client",
"start": "npm run server",
"client": "npm start --prefix client",
"server": "npm start --prefix server",
"server-watch": "npm run watch --prefix server",
"watch": "nodemon server.js --prefix src/server",
"test": "echo \"Error: no test specified\" && exit 1"
},
Client package.json
"scripts": {
"start": "react-scripts start",
"build": "BUILD_PATH='../server/public' react-scripts build ",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
Server package.json
"scripts": {
"install": "npm install",
"start": "node src/server.js",
"watch": "nodemon src/server.js",
"test": "jest",
"test-watch": "jest --watch"
},

Node environment variable for App on docker and Queue Service running on pm2

I have nodejs app running in a docker container. I have set the node environment in package.json
"scripts": {
"start": "node server",
"server": "nodemon server",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"build-client": "npm install --prefix client && npm run build --prefix client",
"prod": "cross-env NODE_ENV=production npm run server"
}
The app is running fine.
But when I'm running a service separately using PM2, even though the node environment is set to production, it's not using the production config.
Below is the config import in service
const Queue = require("../queue/queue");
const connectDB = require("../../config/db");
const constants = require("../constants");
connectDB();

how to configure "npm run-script build" command in Nodejs package.json

I am trying to deploy nextjs based project on AWS EBS, but it is not able to run script "npm run-script build" on server, by this it makes nextjs based build package folder and can run app. here my json.
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "cross-env NODE_ENV=production node server.js"
}
when I deployed my app on server it gives following error.
Error: Could not find a valid build in the '/var/app/current/.next' directory! Try building your app with 'next build' before starting the
server.
I need to run command "npm run-script build" before running app on server, but dosen't aware how to achieve this
simply we can run multiple commands at a time.
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "npm-run-script-build && cross-env NODE_ENV=production node server.js"
}

Start react-create-app and Electron.js with one NPM command

I have simple custom starter pack react-create-app and Electron.js.
I have added to package.json file:
"scripts": {
"electron": "electron .",
"start": "cross-env BROWSER=none react-scripts start",
....
and I can start Electron with npm run electron and React with - npm start.
What I want is to start React and Electron just with one command like: npm run both.
I have tried:
"both": "\"npm start\" \"npm run electron \"",
but I am getting an error in a log file:
Exit status 1 node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)
- nothing specific
I have tried and:
"start": "npm run electron . && cross-env BROWSER=none react-scripts start",
, but this starts the Electron, when I close it, it start the React app.
Again error:
"electron": "electron .",
"start": "cross-env BROWSER=none react-scripts start",
"both": "\"npm run electron\" \"npm run start\"",
I don't know, how to start react-create-app and Electron with just one NPM command ?
Consider utilizing concurrently.
cd to your project directory and run the following command to install it:
npm i -D concurrently
Then redefine the both script in the scripts section of your package.json as follows:
"both": "concurrently \"npm start\" \"npm run electron\""
or the slightly shortened equivalent:
"both": "concurrently \"npm:start\" \"npm:electron\""

How to run one 'npm start' for two different folders in my project directory

I would like to run one npm start command to run both my frontend folder and backend folder. Currently, I have to navigate inside each folder and individually run the command on both to see my app open on the localhost. I have looked into the package 'concurrently' but am having some trouble implementing it in my package.json file.
Here is my package.json file for my frontend folder:
"scripts": {
"start": "set HOST = 'http://localhost' && set PORT=8000 && react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"postbuild": "react-snap"
}
I have tried using this bit to run the backend once I run npm start on the frontend however it did not work:
"start": "set HOST = 'http://localhost' && set PORT=8000 && ../backend/ start & react-scripts start"
Edit:
Still having some troubles after reattempting.
Here are my scripts from my package.json files
Frontend folder
"scripts": {
"start": "set HOST = 'http://localhost' && set PORT=8000 && react-scripts start",
"build": "react-scripts build",
"test": "jest",
"eject": "react-scripts eject",
"postbuild": "react-snap"
},
Backend Folder
"scripts": {
"start": "node ./bin/www"
},
The front end is written in React and the backend in Node. Any help would be greatly appreciated!
Install concurrently:
npm i concurrently --save-dev
Now go to your package.json and add this:
"start": "node index.js",
"client": "npm run start --prefix client",
"dev": "concurrently \"npm run start\" \"npm run client\""
(assuming your client folder contains the front-end server)
then, if you wanna run both servers, just type npm run dev and be happy
I was facing the same issue but it is resolved now. Let's say the server is in the 'Backend' folder and the frontend is in the 'client' folder.
then scripts in server-side package.json should be like:
"scripts": {
"client-install": "npm install --prefix client",
"start": "node server.js",
"server": "nodemon server.js",
"client": "cd ../ && npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\""
},
and client-side package.json is like:
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"proxy": "http://localhost:5000",
then 'npm run dev' runs concurrntly both the server
The 'concurrently' package can do this
npm i concurrently --save-dev
Then set up npm run dev to do
"dev": "concurrently --kill-others \"npm run start-watch\" \"npm run wp-server\""
Another option is to do (Running in Windows CMD):
"dev": "start npm run start-watch && start npm run wp-server"

Resources