{"id":17062338,"url":"https://github.com/devpaul/grunt-devserver","last_synced_at":"2025-04-12T18:12:59.703Z","repository":{"id":5732208,"uuid":"6944149","full_name":"devpaul/grunt-devserver","owner":"devpaul","description":"A simple development web server that serves static content from a directory","archived":false,"fork":false,"pushed_at":"2016-02-20T21:39:22.000Z","size":797,"stargazers_count":14,"open_issues_count":8,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T18:12:51.876Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/devpaul.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":"CONTRIBUTING.md","funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-11-30T19:02:31.000Z","updated_at":"2019-03-31T13:43:24.000Z","dependencies_parsed_at":"2022-08-24T21:40:58.354Z","dependency_job_id":null,"html_url":"https://github.com/devpaul/grunt-devserver","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devpaul%2Fgrunt-devserver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devpaul%2Fgrunt-devserver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devpaul%2Fgrunt-devserver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devpaul%2Fgrunt-devserver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devpaul","download_url":"https://codeload.github.com/devpaul/grunt-devserver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248610341,"owners_count":21132919,"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-10-14T10:49:44.894Z","updated_at":"2025-04-12T18:12:59.664Z","avatar_url":"https://github.com/devpaul.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Developer Web Server\ngrunt-devserver provides a simple way to quickly get a development server serving up your content with\n\n* run from the command line or Grunt 0.4.x\n* no caching content\n* CORS headers for cross-domain requests\n* logs requests to console\n* quickly configure https server\n* redefine your middleware in configuration\n\nAs a developer I needed a lightweight way to serve up client-side applications and content in isolation from a larger\nserver application.  Something that supported a rapid workflow and integrated with my tools.\n\n[![Build Status](https://travis-ci.org/devpaul/grunt-devserver.png?branch=master)](https://travis-ci.org/devpaul/grunt-devserver) [![NPM version](https://badge.fury.io/js/grunt-devserver.png)](http://badge.fury.io/js/grunt-devserver)\n\n## Installation\nInstall it from the command line into your project\n```\nnpm install grunt-devserver --save-dev\n```\nOr install it globally\n```\nnpm install grunt-devserver -g\n```\n\n## Usage\n### From the Command Line\nOnce grunt-devserver has been installed globally you can run it from any folder by typing `devserver`\n\nCommand line options:\n```\n-t, --type (server type) http|https (default is http)\n-p, --port (port number) listen on this port\n-f, --folder (full path to a folder) serves this folder\n-s, --server start a server as defined in the configuration\n--cache (method) the method to return in the Cache-Control HTTP header. Default is no-cache.\n--file (filename) loads a js/json configuration file\n```\n\nFor more information on configuration files see [Configuration Files](#configuration)\n\n### From Grunt \u003ca id=\"grunt\"\u003e\u003c/a\u003e\nTo start a server through grunt you need a devserver configuration in your `Gruntfile.js` and tell\ngrunt to load `grunt-devserver` as an available task. For more information see [Configuring Tasks][Grunt Config].\n```\n    var config = {devserver: {server: {}}}\n    grunt.initConfig(config)\n    grunt.loadNpmTasks('grunt-devserver')\n```\n\nand execute using:\n```\n    grunt devserver\n```\n\nNow you can add the following options:\n```\ndevserver: { options: { 'type' : \u003cstring\u003e (http|https defaults to http)\n                      , 'port' : \u003cport number\u003e (defaults to 8888)\n                      , 'base' : \u003cdirectory\u003e (defaults to .)\n                      , 'cache' : \u003cstring\u003e (defaults to 'no-cache')\n                      , 'httpsOptions' : \u003cobject\u003e https.createServer options\n                      , 'file' : \u003cfilename\u003e\n                      , 'async' : \u003cboolean\u003e (defaults to true)\n                      , 'middleware' : \u003carray\u003e || \u003cfunction\u003e (defaults to predefined middleware)\n                      }\n           }\n```\n\nNOTE: Starting multiple devservers requires setting the `async` option to false so that other server tasks may be\nprocessed.  `async` can also be useful when a server is needed to support integration or functional testing.\n\nSee the [Configuration](#configuration) section for more information.\n\n### From Your Project\nYou can also use devserver directly as a module in your project.\n\n```\n    var devserver = require('grunt-devserver')\n      , options = { type: \"http\", port: 8000 }\n      , serverStarted = devserver(options)\n\n    serverStarted.then(function(server) {\n        // TODO something awesome\n    })\n```\n\n### From WebStorm\nAs a developer tool integration is extremely important.  If you are using a Jetbrains IDE like WebStorm\nhere are instructions to start a devserver directly in your IDE  by adding an entry to your\n[External Tools][jbExternalTools]:\n\n1. Go to Preferences \u003e External Tools\n1. Click Add\n1. Fill in the form:\n    1. name: http\n    1. group: devserver\n    1. program: /usr/local/bin/devserver\n    1. paramters: --port $Prompt$\n    1. working directory: $FileDir$\n1. Hit OK. You should now be able to right-click on any folder and start your devserver!\n\n![WebStorm Usage](./docs/assets/webstorm.png)\n\u003c!-- https://github.com/devpaul/grunt-devserver/tree/master/docs/assets/webstorm.png --\u003e\n\n#### Troubleshooting\n*Q*: I am getting \"`env: node: No such file or directory`\"\n\nYou need to add node to your path.  On a Mac 10.8.x or later [see launchctl man page][launchctl]\n     for more information.\n\n1. From a terminal run ` sudo vim /etc/launchd.conf `\n1. Add ` setenv PATH /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin `\n1. Reboot\n\n## Configuration \u003ca id=\"configuration\"\u003e\u003c/a\u003e\nConfiguration files provide you with the same functionality as a grunt configuration and can easily be shared across\nprojects or used from the command-line.\n\n### Options\n\n#### type\nThe type of server\n\nType: `string`   \nDefault: `http`   \nCommand line: `-t, --type`   \n\n#### port\nThe port where the server will respond\n\ntype: `number`   \ndefault: `8888`   \ncommand line: `-p, --port`   \n\n#### base\nThe base directory of the web server.  This is where files will be served.  This configuration is passed to the\n`serve-index` middleware.\n\ntype: `String`   \ndefault: `'.'`   \ncommand line: `-f, --folder`   \n\n#### cache\nThe type of caching mechanism to use.  The `noCacheHeaders` middleware uses this value to add `Cache-Control`\nheaders to the HTTP response.\n\ntype: `String`   \ndefault: `no-cache`   \ncommand line: `--cache`   \n\n#### httpsOptions\n`httpsOptions` are passed directly through to node's https.createServer() method. [Read the docs for more information][nodehttps].\nThis is ignored unless the server type is specified as `https`.  When a signing certificate is not present, one will be\nautomatically generated.\n\ntype: `object`   \ndefault: none   \n\n#### file\nAs external configuration file. See [Using Configuration Files](#configuration) for samples on how to use file\nconfigurations with devserver\n\ntype: `string`   \ndefault: none   \ncommand line: `--file`   \n\n#### async\n`async` if set to true it will keep Grunt from terminating (see [Grunt Tasks])\n\ntype: `boolean`   \ndefault: `true`   \n\n#### middleware\nRedefines the middleware stack to be used by the server.\n\ntype: `array` or `function`   \ndefault: @see `model/CommonConfig.defaultMiddleware`   \n\nExample: redefine the middleware to log the request and send a hello world message\n```\n{ options: { middleware: [ morgan()\n                         , function(req, res, next) {\n                            res.send('Hello world!').end(200)\n                         }\n                         ]\n           }\n}\n```\n\nRoutes can also be used to define specific middleware handlers\n```\nvar route = require('devserver').middleware.route\nvar morgan = require('morgan')\n\nfunction getName(req, res, next) {\n    // retrieve the user name\n}\n\nfunction putName(req, res, next) {\n    // update the user name\n}\n\n{ options: { middleware: [ morgan()\n                         , route('/name/:id').get(getName).put(putName)\n                         ]\n           }\n}\n```\n\n\n### Option Precedence\nWhen a property exists in the grunt/command-line configuration and in the configuration file, the grunt/command-line\noption always overrides the file options.\n\n### Example\nA example devserverrc file\n```\n{ \"options\": { \"type\" : \"http\"\n             , \"port\" : 8888\n             }\n}\n```\n\nWhen this file is loaded from the command-line\n```\n    devserver --file \"./devserverrc\" --port 4321 --cache \"no-store\"\n```\n\nThe resulting configuration used by devserver\n```\n{ \"options\": { \"type\" : \"http\"\n             , \"port\" : 4321\n             , \"cache\" : \"no-store\"\n             }\n}\n```\n\n[nodehttps]: http://nodejs.org/api/https.html#https_https_createserver_options_requestlistener\n[launchctl]: http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/launchctl.1.html\n[jbExternalTools]: http://www.jetbrains.com/idea/webhelp/external-tools.html\n[Grunt]: http://www.gruntjs.com\n[Grunt Tasks]: http://gruntjs.com/api/inside-tasks#this.async\n[Grunt Config]: http://gruntjs.com/configuring-tasks\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevpaul%2Fgrunt-devserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevpaul%2Fgrunt-devserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevpaul%2Fgrunt-devserver/lists"}