Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running Strapi in process manager doesn't reload the app on saving changes #1008

Closed
1 task done
bartoszgajda55 opened this issue Apr 23, 2018 · 17 comments
Closed
1 task done
Assignees

Comments

@bartoszgajda55
Copy link

bartoszgajda55 commented Apr 23, 2018

Informations

  • Node.js version: 9.11.1
  • npm version: 5.6.0
  • Strapi version: v3.0.0-alpha.12
  • Database: MongoDB
  • Operating system: Ubuntu 16.04

What is the current behavior?
Strapi run using PM2 or Forever doesn't reload on saving content change (like adding new content type) and therefore changes are not seen

Steps to reproduce the problem
Run Strapi using process manager like PM2: pm2 start server.js --name api

What is the expected behavior?
When new content is saved, the app reloads as it does when run using strapi start command
issue

Suggested solutions

  • I'm sure that this issue hasn't already been referenced
@babel626
Copy link

i have the same problem

@lauriejim
Copy link
Contributor

Hello @bartoszgajda55 you just have to use strapi start when you develop your app (using content type builder and custom .js files) there is a file watcher and auto reload.

So if you use pm2 it will not work. It hasn't be design for your use case.

@bartoszgajda55
Copy link
Author

I have Strapi running on VPS and I can't have terminal window open all the time with strapi start command running in it. What would you suggest then ?

@scipe
Copy link

scipe commented Apr 24, 2018

Maybe pm2 --watch help?

@lauriejim
Copy link
Contributor

@bartoszgajda55 you can replace "start": "node_modules/strapi/bin/strapi.js start", in your package.json and then start the app with pm2 start npm -- start

@bartoszgajda55
Copy link
Author

bartoszgajda55 commented Apr 24, 2018

Thanks @lauriejim, that fixed the problem :)

@Luukth
Copy link
Contributor

Luukth commented Apr 25, 2018

Hello, I also found a solution for this problem. With this command you don't have to edit the package.json file. Just make sure you start it inside the strapi project folder.

pm2 start strapi --no-automation --name {{app name}} -- start

@vokvince
Copy link

vokvince commented Sep 6, 2018

Do we have news about the auto restart feature? @lauriejim

@lauriejim
Copy link
Contributor

PR is open here #1854

@Meeken1998
Copy link

i have the same problem, too

@max-ivaneychyk
Copy link

Screenshot from 2019-05-06 19-10-18

try enable autoReload flag
help for me

@alexorbit
Copy link

First

npm install pm2 -g
add server.js to root of your project and write below line:

const strapi = require('strapi');
strapi().start();
save then

pm2 start server.js

@WhereJuly
Copy link

WhereJuly commented Jun 1, 2020

Standing in your Strapi root project run:

pm2 start npm --name process-name-here -- start

Now recall that running Strapi with NPM script is npm run start (see package.json scripts section).

With this in mind let us decompose the pm2 command:

  • pm2 start: starts pm2;
  • npm: npm is run as in the NPM script command above but now via pm2;
  • --name process-name-here: assign your desired name for Strapi process under pm2, see PM2 docs for details;
  • --: required to skip node CLI arguments;
  • start: actually pass start command to NPM script but now via pm2;

Now you have started the Strapi server under PM2 and the former will be restarted whenever the server is rebooted. You can manually restart the process. See the docs link above.

Hope this clarifies things a bit more than just a command line code.

@GabrielSuttner
Copy link

The command is
pm2 start npm --name <process-name-here> -- run develop
pm2 start npm --name strapi-server -- run develop is what my command looked like
This will make it so that the auto reload is enabled so that you can have
Capture
available.

@itsMattShull
Copy link

@GabrielSuttner thanks for that. Does anyone know if there's a production solution?

@derrickmehaffy
Copy link
Member

@GabrielSuttner thanks for that. Does anyone know if there's a production solution?

The CTB is disabled in staging and production: https://strapi.io/documentation/v3.x/getting-started/troubleshooting.html#why-can-t-i-create-or-update-content-types-in-production-staging

@MyKrzysiu
Copy link

const strapi = require('strapi');

strapi({
    autoReload: true,
    serveAdminPanel: true
}).start();

If you start with server.js, try it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests