{"id":13647514,"url":"https://github.com/ericclemmons/grunt-express-server","last_synced_at":"2025-04-12T18:42:57.724Z","repository":{"id":7104490,"uuid":"8397014","full_name":"ericclemmons/grunt-express-server","owner":"ericclemmons","description":"Grunt task for running an Express Server that works great with LiveReload + Watch/Regarde","archived":false,"fork":false,"pushed_at":"2018-02-21T22:20:29.000Z","size":106,"stargazers_count":249,"open_issues_count":21,"forks_count":60,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-06T07:15:41.484Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ericclemmons.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-02-24T21:22:57.000Z","updated_at":"2025-03-23T22:57:44.000Z","dependencies_parsed_at":"2022-09-04T19:24:38.968Z","dependency_job_id":null,"html_url":"https://github.com/ericclemmons/grunt-express-server","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericclemmons%2Fgrunt-express-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericclemmons%2Fgrunt-express-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericclemmons%2Fgrunt-express-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericclemmons%2Fgrunt-express-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericclemmons","download_url":"https://codeload.github.com/ericclemmons/grunt-express-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248617127,"owners_count":21134190,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T01:03:37.071Z","updated_at":"2025-04-12T18:42:57.658Z","avatar_url":"https://github.com/ericclemmons.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# grunt-express-server\n\n[![Build Status](https://travis-ci.org/ericclemmons/grunt-express-server.png?branch=master)](https://travis-ci.org/ericclemmons/grunt-express-server)\n[![Dependencies](https://david-dm.org/ericclemmons/grunt-express-server.png)](https://david-dm.org/ericclemmons/grunt-express-server)\n[![devDependencies](https://david-dm.org/ericclemmons/grunt-express-server/dev-status.png)](https://david-dm.org/ericclemmons/grunt-express-server#info=devDependencies\u0026view=table)\n\n\u003e Simple grunt task for running an Express server that works great with LiveReload + Watch/Regarde\n\n## Getting Started\n\nThis plugin requires Grunt `\u003e=0.4.0`\n\nIf you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:\n\n```shell\nnpm install grunt-express-server --save-dev\n```\n\nOnce the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:\n\n```js\ngrunt.loadNpmTasks('grunt-express-server');\n```\n\n## The `express` task\n\n### Setup\n\nIn your project's Gruntfile, you can create one or multiple servers:\n\n```js\ngrunt.initConfig({\n  express: {\n    options: {\n      // Override defaults here\n    },\n    dev: {\n      options: {\n        script: 'path/to/dev/server.js'\n      }\n    },\n    prod: {\n      options: {\n        script: 'path/to/prod/server.js',\n        node_env: 'production'\n      }\n    },\n    test: {\n      options: {\n        script: 'path/to/test/server.js'\n      }\n    }\n  }\n});\n```\n\nYou can override the default `options` either in the root of the `express` config\nor within each individual server task.\n\n### Default `options`\n\n```js\n  express: {\n    options: {\n      // Override the command used to start the server.\n      // (do not use 'coffee' here, the server will not be able to restart\n      //  see below at opts for coffee-script support)\n      cmd: process.argv[0],\n\n      // Will turn into: `node OPT1 OPT2 ... OPTN path/to/server.js ARG1 ARG2 ... ARGN`\n      // (e.g. opts: ['node_modules/coffee-script/bin/coffee'] will correctly parse coffee-script)\n      opts: [ ],\n      args: [ ],\n\n      // Setting to `false` will effectively just run `node path/to/server.js`\n      background: true,\n\n      // Called when the spawned server throws errors\n      fallback: function() {},\n\n      // Override node env's PORT\n      port: 3000,\n\n      // Override node env's NODE_ENV\n      node_env: undefined,\n\n      // Enable Node's --harmony flag\n      harmony: false,\n\n      // Consider the server to be \"running\" after an explicit delay (in milliseconds)\n      // (e.g. when server has no initial output)\n      delay: 0,\n\n      // Regular expression that matches server output to indicate it is \"running\"\n      output: \".+\",\n\n      // Set --debug (true | false | integer from 1024 to 65535, has precedence over breakOnFirstLine)\n      debug: false,\n\n      // Set --debug-brk (true | false | integer from 1024 to 65535)\n      breakOnFirstLine: false,\n\n      // Object with properties `out` and `err` both will take a path to a log file and\n      // append the output of the server. Make sure the folders exist.\n      logs: undefined\n\n    }\n  }\n```\n\n### Usage\n\nBy default, unless `delay` or `output` has been customized,\n**the server is considered \"running\" once any output is logged to the console**,\nupon which control is passed back to grunt.\n\nTypically, this is:\n\n\u003e Express server listening on port 3000\n\nIf your server doesn't log anything, the express task will never finish and **none** of the following tasks, after it, will be executed. For example - if you have a development task like this one:\n\n```javascript\ngrunt.registerTask('rebuild', ['clean', 'browserify:scripts', 'stylus', 'copy:images']);\ngrunt.registerTask('dev', ['rebuild', 'express', 'watch']);\n```\n\nIf you run the dev task and your server doesn't log anything, **'watch' will never be started**.\n\nThis can easily be avoided, if you log something, when server is created like that:\n\n```javascript\nvar server = http.createServer( app ).listen( PORT, function() {\n    console.log('Express server listening on port ' + PORT);\n} );\n```\n\nIf you log output *before* the server is running, either set `delay` or `output` to indicate\nwhen the server has officially started.\n\n#### Starting the server\n\nIf you have a server defined named `dev`, you can start the server by running `express:dev`. The server only runs as long as grunt is running. Once grunt's tasks have completed, the web server stops.\n\n#### Stopping the server\n\nSimilarly, if you start the `dev` server with `express:dev`, you can stop the server\nwith `express:dev:stop`.\n\n#### With [grunt-contrib-watch](https://github.com/gruntjs/grunt-contrib-watch)\n\n```js\ngrunt.initConfig({\n  watch: {\n    express: {\n      files:  [ '**/*.js' ],\n      tasks:  [ 'express:dev' ],\n      options: {\n        spawn: false // for grunt-contrib-watch v0.5.0+, \"nospawn: true\" for lower versions. Without this option specified express won't be reloaded\n      }\n    }\n  }\n});\n\ngrunt.registerTask('server', [ 'express:dev', 'watch' ])\n```\n\n**Important:** Note that the `spawn: false` options only need be applied to the watch target regarding the express task.\nYou may have other watch targets that use `spawn: true`, which is useful, for example, to reload CSS and not LESS changes.\n\n```js\nwatch: {\n  options: {\n    livereload: true\n  },\n  express: {\n    files:  [ '**/*.js' ],\n    tasks:  [ 'express:dev' ],\n    options: {\n      spawn: false\n    }\n  },\n  less: {\n    files: [\"public/**/*.less\"],\n    tasks: [\"less\"],\n    options: {\n      livereload: false\n    }\n  },\n  public: {\n    files: [\"public/**/*.css\", \"public/**/*.js\"]\n  }\n}\n```\n\n## Contributing\n\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).\n\n## Release History\n\n- v0.5.3 - Update peerDeps and enable travis build against Node 4\n- v0.5.2 - Add `hardStop` flag ([#99](https://github.com/ericclemmons/grunt-express-server/pull/99))\n- v0.5.1 - Add `harmony` flag ([#86](https://github.com/ericclemmons/grunt-express-server/pull/86))\n- v0.5.0 - Add breakOnFirstLine option, support for debug ports and fix bugs. Details: ([#68](https://github.com/ericclemmons/grunt-express-server/pull/68), [#70](https://github.com/ericclemmons/grunt-express-server/pull/70), [#73](https://github.com/ericclemmons/grunt-express-server/pull/73))\n- v0.4.19 – Use `process.env.PORT` before `3000` ([#59](https://github.com/ericclemmons/grunt-express-server/pull/59))\n- v0.4.18 – Fix for when running the node debugger ([#57](https://github.com/ericclemmons/grunt-express-server/pull/57))\n- v0.4.17 – Update `devDependencies`...again\n- v0.4.16 – Update `devDependencies`\n- v0.4.15 – Recommend using local `coffee` with additional arguments ([#50](https://github.com/ericclemmons/grunt-express-server/pull/50))\n- v0.4.14 – Attempt to fix issues running Coffeescript ([#54](https://github.com/ericclemmons/grunt-express-server/pull/54))\n- v0.4.13 – Add `--nodejs` for Coffeescript users ([#37](https://github.com/ericclemmons/grunt-express-server/issues/37))\n- v0.4.12 – Only remove this task's listeners ([#39](https://github.com/ericclemmons/grunt-express-server/pull/39))\n- v0.4.11 – Revert v0.4.10 until Travis can reproduce it\n- v0.4.10 – Another attempt to fix #28 \u0026 #30's server restarting issue ([#31](https://github.com/ericclemmons/grunt-express-server/pull/31))\n- v0.4.9 – Revert v0.4.8 until [#30](https://github.com/ericclemmons/grunt-express-server/issues/30#issuecomment-29931192) is resolved\n- v0.4.8 – Fix issue with start/restarting multiple instances ([#29](https://github.com/ericclemmons/grunt-express-server/pull/29))\n- v0.4.7 – Remove broken `error` option ([#27](https://github.com/ericclemmons/grunt-express-server/issues/27))\n- v0.4.6 – Store running servers on `process._servers[target]` ([#22](https://github.com/ericclemmons/grunt-express-server/issues/22))\n- v0.4.5 – Support multiple servers running at once ([#23](https://github.com/ericclemmons/grunt-express-server/pull/23))\n- v0.4.4 - Fix for using `grunt-env` to change environments, thanks to @FredrikAppelros ([#20](https://github.com/ericclemmons/grunt-express-server/pull/20))\n- v0.4.3 - Add `cmd` option that defaults to Node, but can be set to `coffee` for Coffeescript support, thanks to @JonET ([#15](https://github.com/ericclemmons/grunt-express-server/pull/15))\n- v0.4.2 - Add `debug` option that gets enables Node's debugger, ideally for use with [node-inspector](https://github.com/node-inspector/node-inspector)\n- v0.4.1 - Add `node_env` option that sets `NODE_ENV` when running the server \u0026 restores original env upon closing, thanks to @jgable!\n- v0.4.0\n  - Add `delay` option that, when set, passes control back to grunt after timeout\n  - Add `output` regular expression option that, when set, waits for matching message before passing control back to grunt\n- v0.3.1 - Try to force notification that `express` task has finished as much as possible\n- v0.3.0 - `express` is now a multitask with customizable options, better error handling and `:stop` task\n- v0.2.0\n  - Change `express-server` task to `express`\n  - Config is set via `express: '...'` instead of `server: { script: '...' } `\n- v0.1.0 - Initial import from [Genesis Skeleton](https://github.com/ericclemmons/genesis-skeleton) \u0026 release\n\n\n[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/ericclemmons/grunt-express-server/trend.png)](https://bitdeli.com/free \"Bitdeli Badge\")\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericclemmons%2Fgrunt-express-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericclemmons%2Fgrunt-express-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericclemmons%2Fgrunt-express-server/lists"}