Scenario
I've made react app as well as a express server for API and both are separate. I've not included react folder in express app. I'm looking forward to deploy it using pre/post scripts using PM2 but I'm having hard time achieving exactly what is in my mind.
Goal
- I want to run npm install for both client and server as I might remove/add package if needed later.
- I'm thinking like after npm install I want to build react app and then move that folder for serving to express( I don't know if it's possible to give directory path which is out of parent for express static contents).
- Then I want to start the express server which will eventually serve react build files.
For now my directory structure is
.
├── client
├── ecosystem.config.js
└── server
I'm mostly confused as I don't came across any resource where this is achieved. Also I'm not sure if this is even possible with pm2 deploy scripts or I need to write my own bash script which will do some stuff then pm2 will only start server.
This is only what I did which seems totally wrong
ecosystem.config.js
module.exports = {
apps : [{
name: 'API',
cwd: 'server',
script: 'server.js',
args: 'one two',
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: '1G',
env_production: {
NODE_ENV: 'production'
}
}],
deploy : {
production : {
user : 'node',
// host : '212.83.163.1',
// ref : 'origin/master',
// repo : '[email protected]:repo.git',
// path : '/var/www/production',
'post-deploy' : 'cd client && npm run build'
}
}
};
grunt
orgulp
) in order to achieve this. And create the respective deployment scripts for the same and order them accordingly. – Cervelat