Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

server not stopping before restart when editing Gruntfile.js #22

Closed
pensierinmusica opened this Issue · 6 comments

3 participants

@pensierinmusica

Hi,

I have Grunt "watch" looking at some files and restarting Express if they get changed.

It all works seamlessly. For some weird reason though if the file edited is Gruntfile.js, grunt-express-server doesn't stop Express before relaunching when the express:dev task is triggered by grunt-watch and obviously it generates an EADDRINUSE error.

This is my grunt-watch configuration:

    watch: {
      options: {
        livereload: true
      },
      stylus: {
        files: ['<%= yeoman.app %>/styles/sections/*.styl'],
        tasks: ['stylus'],
        options: {livereload: false}
      },
      autoprefixer: {
        files: ['<%= yeoman.app %>/styles/*.css'],
        tasks: ['autoprefixer']
      },
      express: {
        files: [
          'app.js',
          'config/*.js',
          'controllers/*.js',
          'models/*.js',
          'Gruntfile.js'
        ],
        tasks: ['express:dev'],
        options: {spawn: false} // Without this option specified express won't be reloaded
      }

And this is my grunt-express-server configuration:

    express: {
      options: {
        port: process.env.PORT || 3000
      },
      dev: {
        options: {
          script: 'app.js'
        }
      },
      prod: {
        options: {
          script: 'app.js',
          node_env: 'production'
        }
      }
    }

The weird thing is that the problem ony happens with Gruntfile.js. If I modify, let's say, app.js or one of the controllers, the task correctly stops Express before reloading it.

Any thoughts?? Thanks!

@ericclemmons

I'm not really sure yet, but I have to ask, why restart the server if the Gruntfile changes?

@pensierinmusica

I guess you're right... I could just live-reload the browser :)

@jalcine

I'm having this issue when I'm editing my package.json and wanting to reload the server to include new packages like middleware and the likes.

@ericclemmons
Owner

Wow, that's really odd! I was able to reproduce it, & trying to figure out why Gruntfile.js changes would cause this!

@ericclemmons
Owner

Apparently Gruntfile.js is auto-watched, which doesn't properly emit the proper signals to kill the server. As a result, the next iteration of watch seems to run the task in a new namespace, meaning the server never shuts down.

Trying an alternative now...

@ericclemmons
Owner

Aha! Stupid Grunt being clever. I'm having to introduce process._servers to keep the server in memory for stopping, since Grunt explicitly clears the require cache.

@ericclemmons ericclemmons closed this issue from a commit
@ericclemmons Store running servers on `process._servers[target]`.
Because modifications to Gruntfile.js automatically
clears `require.cache`, all server references were
lost.

Closes #22
dd0acdf
@ericclemmons ericclemmons was assigned
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.