gruntjs - How can I use the grunt-express for express 4.12? -
i use express 4.12 build project , want use grunt-express start application. have known express 4.12 start application via node ./bin/www, write gruntfile.js this:
express: { dev: { options: { port: 3000, bases: path.resolve('bin/'), server: path.resolve('bin/www') } } } grunt.loadnpmtasks('grunt-express') grunt.registertask('default', ['express', 'express-keepalive']);
unfortunately, when run grunt, reports error:
fatal error: server should provide function called "listen" acts http.server.listen
but found in www file, there function "listen":
var server = http.createserver(app) server.listen(port);
i confused this. please teach me write gruntfile.js www file?
the grunt-express
server option expects see express app, not bin/www
is. if @ bin/www
, requiring express app? eg, should app.js
in project root, or maybe server/index.js
.
also, bases
shouldn't bin
, rather should pointing public static resources dir, eg /public
or if have build step generates minified stuff might /dist
.
try (editing server , bases match project):
grunt.initconfig({ express: { options: { port: 3000, hostname: 'localhost' }, dev: { options: { server: path.resolve('./app.js'), bases: [path.resolve('./public')] } } } });
Comments
Post a Comment