GithubHelp home page GithubHelp logo

Comments (13)

ericclemmons avatar ericclemmons commented on August 16, 2024

I'll work on this once I get to work!

from grunt-express-server.

uorbe001 avatar uorbe001 commented on August 16, 2024

I think I figured out (part) of the issue, I am calling express' app.listen with a callback and printing a custom message on success, this is probably not being caught by the output regexp on grunt-express-server, because without it, the server starts without automatically stopping (It doesn't return control of the shell though, is it supposed to?). This doesn't solve the issue with the server stop though, I still get a EADDINUSE and an error that seems to imply it is trying to start the server again.

from grunt-express-server.

ericclemmons avatar ericclemmons commented on August 16, 2024

Hey @uorbe001, background is true by default, so can you help me out with the following:

  • Your express:assets config block
  • The grunt express:assets ... command that I can use the debug the problem

?

from grunt-express-server.

ericclemmons avatar ericclemmons commented on August 16, 2024

Here's a project that may help show how I'm using it for now:

https://github.com/ericclemmons/genesis-skeleton

I never call :stop, because the server stops on its own when the task is called again.

You can customize the output option to match your script, though it defaults to /.+/ currently.

Can you help me out with my previous 2 requests so I can help debug this?

from grunt-express-server.

uorbe001 avatar uorbe001 commented on August 16, 2024

@ericclemmons Thanks for the help.

Not sure what you mean by the grunt command, the commands I'm running are grunt express:assets to start the server and grunt express:assets:stop to stop it. Starting the server with the callback and custom message on listen results in what I got on my original message, but I think this might be a problem with me outputting to the wrong stream or something like that (was simply using console.log, might be that isn't the right thing to use here). Without the listen callback, what I get is the server starting the task but doesn't give me control over the shell, which isn't the behavior I expected (but might be right).

When I stop the server, I always get the EADDINUSE, am looking into your project to see if I can make the server stop automatically when the task is called too, but I'd rather not leave the server running if possible O:)

My express config block:

express: {
    dev: {
      options: {
        script: 'app/server.js'
      }
    },

    assets: {
      options: {
        script: 'spec/support/server.js',
        background: true
      }
    }
}

This is the server file just in case you can spot something wrong:

var express = require("express");
var app = express();

app.configure(function () {
    app.use(express.static(__dirname + '/static'));
});

module.exports = app.listen(6543);

from grunt-express-server.

ericclemmons avatar ericclemmons commented on August 16, 2024

Alright, so a couple of things:

  • background: true shouldn't be necessary, it's the default. Setting it to false basically says "no matter what the server spits out, keep it running until it exits on its own".
  • Try adding the option delay: 1000 and see if that resolves the behavior.
  • Append a callback to app.listen that logs something
module.exports = app.listen(6543, function() {
  console.log("Express server listening on port " + app.get('port'));
});

from grunt-express-server.

uorbe001 avatar uorbe001 commented on August 16, 2024

@ericclemmons I tried adding that callback to the listen (and removed the background from my grunt config), and it doesn't change anything, it still exists the server as soon as it is started. Adding the delay doesn't seem to change anything for me either.

As for the background option, it doesn't sound like it does what I thought it did, so thanks for the clarification :)

I tried getting your commit 01ed2d3 and I get the same behavior I get with my code, both with the callback and without it. In case it helps, I'm using node 0.10.4 (with nvm).

from grunt-express-server.

ericclemmons avatar ericclemmons commented on August 16, 2024

At this point, I think you'll have to provide a simple project that I can test and fix it with.

from grunt-express-server.

uorbe001 avatar uorbe001 commented on August 16, 2024

@ericclemmons I can replicate both problems with:

  1. git clone https://github.com/ericclemmons/grunt-express-server.git
  2. cd grunt-express-server
  3. git checkout 01ed2d3
  4. npm install
  5. grunt express:quiet

This causes the terminal to show the server started but doesn't give me shell control back:

Running "express:quiet" (express) task
Starting background Express server

At this point, if I run grunt express:quiet:stop from another shell, I get the EADINUSE error.

For the start & stop error, I can repeat steps 1-4 from before and:

  1. modify test/server-quiet.js to this:
"use strict";

/**
 * Test Server
 */

var app   = require('./app');

module.exports = app.listen(app.get('port'), function() { console.log('something'); });
  1. grunt express:quiet

That prints this for me:

Running "express:quiet" (express) task
Starting background Express server
something

Done, without errors.
Stopping Express server

As I said, I'm using node v0.10.4 installed with nvm, in case it helps. I can try to make a sample project, but given that I can replicate it with that same code, I don't see how it would help?

from grunt-express-server.

ericclemmons avatar ericclemmons commented on August 16, 2024

That's enough for me! Let me see what happens on my end. Thank you!

from grunt-express-server.

ericclemmons avatar ericclemmons commented on August 16, 2024
  1. Starting grunt __anything__ does not know about anything you do in another grunt __something__ window. If you want to stop the server, just simply Ctrl-C the grunt process on the original window.
  2. The way grunt works, running express:quiet:stop will fall back to express:quiet, starting the server, when there's no pre-existing server running.
  3. Grunt tasks are made to run, complete, and hand control back to grunt. In your last example, you're starting a server, the control gets passed to grunt, there's no remaining tasks to run, so grunt exits, thereby causing express to exit. If you want to run a server, just run node path/to/server.js or npm start or equivalent. If you want the task to keep the server running until you break via Ctrl-C, set options: { background: false; }, which will run the express server in the foreground and keep control away from grunt until you cancel the process.

The normal use case for this task (and almost every other grunt or Yeoman task) is something like:

$ grunt clean less concat minify express watch

watch is the task that keeps grunt running and calls express repeatedly upon changes.

Does that make sense now?

from grunt-express-server.

uorbe001 avatar uorbe001 commented on August 16, 2024

@ericclemmons That makes sense, thanks for the help and the clarification. I tried running the express tasks on a more 'complex' task as I intended originally, and it works as expected when I add any output on the callback for the app.listen. If I don't have a callback on the listen, the 'complex' task seems to get stuck as soon as it starts the server though (I get no output after the "Starting background express server"), but this might be an issue with my task.

from grunt-express-server.

Agterra avatar Agterra commented on August 16, 2024

Hey, quite a bit late, but have you tried changing the port ? because the error code EADINUSE makes me think of that.

from grunt-express-server.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.