How to run Strapi in DEV mode with forever?

Hello,
I have created a file in the root directory for Strapi app called (server.js) with the code below. I couldn’t find any documentation that explains how to run the application in development mode through using “forever” process manager.

Code of server.js:

const strapi = require('strapi');

// start strapi application
strapi().start();

if I use “start()” it runs as production and I can’t edit the content-types. I need to have the application running with or without the “watch” in dev.

Thanks

System Information
  • Strapi Version: 3.6.5
  • Operating System: Debian
  • Database: Mysql
  • Node Version: v12.20.2
  • NPM Version: 6.14.11
  • Yarn Version: 1.22.10

Not sure how forever works, but as an alternative, you can try pm2.

Create a file ecosystem.config.js in the project’s root directory with content:

module.exports = {
  apps: [
    {
      name: 'you-app-name',
      script: 'npm',
      args: 'develop',
      env: {
        NODE_ENV: 'development',
      },
      exp_backoff_restart_delay: 100,
    },
  ],
};

Now you can run the app with the command:
pm2 start ecosystem.config.js

thanks for the response @sunnyson but unfortunately, it doesn’t work. Here’s what I did:

  1. installed pm2 (sudo npm install pm2 -g)
  2. from the app root directory (pm2 init)
  3. I edited the file "ecosystem.config.js) and replaced its content with the code you provided.
module.exports = {
  apps: [
    {
      name: 'you-app-name',
      script: 'npm',
      args: 'develop',
      env: {
        NODE_ENV: 'development',
      },
      exp_backoff_restart_delay: 100,
    },
  ],
};

I don’t know if I have to create an env variable or something but it’s still not working. Instead, I’m doing (pm2 start “yarn develop” ) and that works fine but I would like to work with the config file for future work.

Question: Why are you trying to run the development mode continuously?

Why I ask: this isn’t an environment that we generally support, simply because Strapi is designed so that development happens locally (hence why the content-type builder is disabled in other environments)

The sole purpose is to have a shared dev environment accessible for all developers. It’s going to be hard to replicate the data in DB in all local machines. When a developer builds something and pushes code to a repo, it’s hard for other stakeholders to test, add data, etc. This helps everyone to see changes on the fly.

For instance, when a developer creates a collection, another person can add the data. then, both can test the APIs and continue the development.

1 Like

This will be less of an issue once we get to the v4 since we will handle all the database table/column migrations automatically.

1 Like

I’ve removed the gitignore line for the sqlite file and just commit .tmp/data.db to my repo. Not fancy but works wonders to keep data in sync since I’m the only dev but working in different computers. Another solution in the same line could be a common cloud DB for all devs.

1 Like

Thanks for posting this. This echoes the issue I’m having - I thought we need to run the heroku-hosted strapi in dev mode so that content can be created via the web UI. So I’m new to strapi and built a local instance, then pushed it to host on Heroku. We want a centralized CMS that our content authors can sign into and create content - we definitely don’t want and can’t have our authors pushing changes via github. Forgive me for hijacking this response, but after reading the forum I wasn’t able to find the right doc about deployment strategy. Any response is much appreciated.

1 Like

But content authors can create and edit content at will in production. They can’t create or change the building blocks of content in production.

1 Like

Thanks so much for responding in. We’re getting this “autoreload required” error on our heroku environment when I gave out access to a content creator, so that’s why I thought we had to run in ‘dev’ mode.

That means they are trying to modify the models not the content and that will not work in production mode, and 110% won’t work in Heroku at all, period. Even in dev mode it won’t work in Heroku due to their filesystem.

See: Troubleshooting - Strapi Developer Documentation

1 Like

I’m using AWS LightSail and it works great. It’s cheap, quick to set up.

1 Like

I went with an AWS deployment too. Still putting finishing touches on it but I’m happy with the decision.

1 Like