Comments (30)
So it's starting up fine, but watch triggers express
again and it fails for you? I'll check 'er out!
from grunt-express-server.
Hi Eric,
Yes, that's right. I've tried disabling the tasks that get run before hand to see if they were interfering some how but no joy….
Cheers!
Dom
On 4 Aug 2013, at 17:59, Eric Clemmons [email protected] wrote:
So it's starting up fine, but watch triggers express again and it fails for you? I'll check 'er out!
—
Reply to this email directly or view it on GitHub.
from grunt-express-server.
any luck with this?
Cheers,
Dom
from grunt-express-server.
Had the same issue, the problem might be that even though your server receives SIGTERM, it might not be exiting because of opened connections or listeners... SIGTERM is a polite way of asking a process to exit... so in process.on 'SIGTERM'
add process.exit()
from grunt-express-server.
What's so bizarre is that in my testing, you would expect grunt express:defaults express:defaults express:defaults
to exhibit this behavior, right?
I just added grunt-contrib-watch
, with ['jshint', 'express:defaults']
, and no matter how I try, grunt express:defaults watch
won't trigger the EADDRINUSE error.
I need some more help here...
from grunt-express-server.
@Dakuan Can you post up your app.js
so I can see if there's any hints there? Particularly the app.listen
part...
from grunt-express-server.
I'm having the same problem. Are there any workarounds?
from grunt-express-server.
Sure, there are totally some workarounds, and possibly some fixes! If only someone could point me to a project or example code for me to reproduce the problem with :)
:hint hint:
from grunt-express-server.
I'm going to have to close this issue until someone can help me reproduce it. I may run across it on my own, but until then, you guys are going to have to help me out here :)
from grunt-express-server.
@ericclemmons - I'm having this issue now. Here is what I have:
Gruntjs Snippet
// Define Server
express: {
options: {
// Override defaults here
},
dev: {
options: {
script: 'express.js'
}
}
},
// Setup Watch
watch: {
express: {
files: [ 'server/**/*.js' ],
tasks: [ 'express:dev' ],
options: {
spawn: false // Without this option specified express won't be reloaded
}
}
};
grunt.registerTask('server', ['express:dev', 'watch']);
express.js
var express = require('express'),
app = express();
// Start the server
app.listen(3000, function () {
console.log("Express server listening on port %d in %s mode", 3000, app.settings.env);
});
I don't think you can get much simpler than this.
from grunt-express-server.
Just having a look at your /tasks/lib/server.js
. I've done console.log(process._servers);
just above line 12. When it first starts up, I get undefined
, which is what we want. But when a file is edited and watch triggers the server again, that _servers
object is still undefined. I'm guessing that it shouldn't be. Maybe something changed recently in grunt-contrib-watch
that no longer persists the data in process
? I've never written a grunt task, so I could be talking complete nonsense.
from grunt-express-server.
Do me a favor & add module.exports = app.listen(...)
in front of your code & let me know if that changes anything...
from grunt-express-server.
Do me a favor & add module.exports = app.listen(...) in front of your code & let me know if that changes anything...
Nope, doesn't work.
from grunt-express-server.
Ok, back to me then ;)
from grunt-express-server.
Just wondering if you've had a chance to look at this? It would be super handy if it worked :).
from grunt-express-server.
Sorry, been ill for several days. I'll get to this soon.
from grunt-express-server.
Hi @ericclemmons,
Sorry to hear that! No worries, take your time.
Cheers,
cody
from grunt-express-server.
Just published v0.4.10 with #31 (fixes #28 & #30). Can you let me know if this also resolves your problem, or if it persists?
from grunt-express-server.
Hi @ericclemmons,
Sorry, but this is not fixed. It's still not killing off the server before trying to restart it.
from grunt-express-server.
@meenie I had to revert v0.4.10 because of #32. Please confirm this problem persists with v0.4.11, as I'll need to create test cases specifically for grunt-contrib-watch
.
from grunt-express-server.
Wait a minute here. Is everyone using the spawn
/nospawn
option?
https://github.com/ericclemmons/grunt-express-server#with-grunt-contrib-watch
from grunt-express-server.
@ericclemmons yes - I have spawn
set to false
.
from grunt-express-server.
@ericclemmons for info, I'm trying to integrate it into ngBoilerplate: https://github.com/ngbp/ng-boilerplate
from grunt-express-server.
@ericclemmons I saw your comment with the code example using nospawn: true
(It seems you've deleted it though? I saw it in the email alert you get when there is a new comment on an issue). So I put it in and now everything works.
So the conclusion is:
spawn: false
doesn't worknospawn: true
does work
from grunt-express-server.
grunt-contrib-watch changed nospawn to spawn, and they should pretty much just do the inverse of the other. So, I'm not sure why they'd have different behavior.
Man, I have to say, Grunt's watch behavior is pretty annoying when it comes to managing processes. It's a freakin' minefield.
from grunt-express-server.
fixed for me too!
from grunt-express-server.
I had trouble getting this to work for me, but found an alternate solution that may help others:
watch: {
express: {
files: ['src/server/**/*.js'],
tasks: ['express:dev'],
options: {
atBegin: true, // when watcher loads, run tasks once
spawn: false //still req'd
}
}
}
express: {
dev: {
options: {
script: 'src/server/http-server.js'
}
}
}
grunt.registerTask('start', ['watch:express']);
options.atBegin
for grunt-contrib-watch relieves you of needing to run the task once before setting the watcher, since the watcher will now do it for you when it loads.
Allowing watch
this extra bit of control around task execution seemed to resolve the conflict for me, and also simplified my task lists - nice to be able to specify just the watch.
from grunt-express-server.
So... Sorry to resurrect a zombie, but just wanted to confirm that the problem is specifically this line from @meenie
grunt.registerTask('server', ['express:dev', 'watch']);
Which is fixed by removing the express:dev
from boot and using atBegin:true
as @eviljohnius mentioned in comment #42258252
from grunt-express-server.
Looks like this could be a FAQ :)
I had this symptom when using babel-node to start an (ES6) server. I was using this configuration:
dev: {
options: {
opts: ['node_modules/babel/bin/babel-node'],
port: 8282,
script: 'server.js'
}
}
After trying all other suggestions in this thread, I added a babel-node shim. This worked:
dev: {
options: {
port: 8282,
script: 'app.js'
}
}
app.js:
require('babel/register')({stage: 0});
require('./server');
from grunt-express-server.
Now that's interesting. I expected the babel-node
binary would work.
from grunt-express-server.
Related Issues (20)
- using traceur as preprocessor HOT 6
- add restart option HOT 2
- initial server not closed HOT 4
- Fatal error: Cannot read property 'hardStop' of null HOT 8
- Express server crashes unexpectedly, no error log HOT 2
- Settings backround to true doesn't keep the server running HOT 3
- not running correct app; cwd problems HOT 2
- Pass args to non-background process is restricted
- fallback implementation question HOT 6
- THE NEW REPO TO CONTINUE THIS GRUNT TASK
- --debug is deprecated HOT 4
- Can't find the default port of grunt-express-server HOT 1
- is it possible to integrate bunyan's CLI with this? HOT 2
- How to use when console.log outputs to file
- Server is stopped. HOT 1
- Output loses formatting HOT 3
- No page refresh but all else works HOT 3
- Specifying a port is ignored HOT 1
- Error: listen EADDRINUSE HOT 2
- Looking for Contributors / Owners HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grunt-express-server.