{"_id":"node-static-alias","_rev":"4658025","name":"node-static-alias","description":"Serve static file which is not requested file. (e.g. `file.min.js` is requested, serve `file.js`)","dist-tags":{"latest":"1.1.2"},"maintainers":[{"name":"anseki","email":""}],"time":{"modified":"2026-04-10T21:24:21.000Z","created":"2013-12-29T14:57:11.309Z","1.1.2":"2018-05-28T02:39:31.141Z","1.1.1":"2018-05-26T05:17:06.407Z","1.1.0":"2018-05-26T04:55:46.934Z","1.0.0":"2017-02-03T11:21:21.521Z","0.1.3":"2015-05-28T06:04:55.312Z","0.1.2":"2014-10-23T20:28:56.046Z","0.1.1":"2014-06-26T23:53:43.905Z","0.1.0":"2013-12-29T14:57:11.309Z"},"users":{},"author":{"name":"anseki","url":"https://github.com/anseki"},"repository":{"type":"git","url":"git://github.com/anseki/node-static-alias.git"},"versions":{"1.1.2":{"name":"node-static-alias","version":"1.1.2","title":"node-static-alias","description":"Serve static file which is not requested file. (e.g. `file.min.js` is requested, serve `file.js`)","keywords":["http","httpd","test","static","file","server","alias","mod_rewrite","directoryindex","min","log"],"main":"./lib/node-static-alias.js","files":["lib/!(.eslintrc.json)","example/!(.eslintrc.json)","ss.png"],"engines":{"node":">= 0.8.0"},"dependencies":{"node-static":"~0.7.2"},"homepage":"https://github.com/anseki/node-static-alias","repository":{"type":"git","url":"git://github.com/anseki/node-static-alias.git"},"bugs":{"url":"https://github.com/anseki/node-static-alias/issues"},"license":"MIT","author":{"name":"anseki","url":"https://github.com/anseki"},"gitHead":"550e6d8664b275a039e688fca306500e1602a523","_id":"node-static-alias@1.1.2","_npmVersion":"5.6.0","_nodeVersion":"8.11.1","_npmUser":{"name":"anseki","email":"AnSeki.aff@gmail.com"},"maintainers":[{"name":"anseki","email":""}],"dist":{"shasum":"7ba467e188dc7182ba42815a939a0b149c5d4302","size":14023,"noattachment":false,"key":"/node-static-alias/-/node-static-alias-1.1.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-static-alias/download/node-static-alias-1.1.2.tgz"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/node-static-alias_1.1.2_1527475170944_0.3012294345011437"},"_cnpmcore_publish_time":"2021-12-23T07:14:53.614Z","publish_time":1527475171141,"_cnpm_publish_time":1527475171141},"1.1.1":{"name":"node-static-alias","version":"1.1.1","title":"node-static-alias","description":"Serve static file which is not requested file. (e.g. `file.min.js` is requested, serve `file.js`)","keywords":["http","httpd","test","static","file","server","alias","mod_rewrite","directoryindex","min","log"],"main":"./lib/node-static-alias.js","files":["lib/!(.eslintrc.json)","example/!(.eslintrc.json)"],"engines":{"node":">= 0.8.0"},"dependencies":{"node-static":"~0.7.2"},"homepage":"https://github.com/anseki/node-static-alias","repository":{"type":"git","url":"git://github.com/anseki/node-static-alias.git"},"bugs":{"url":"https://github.com/anseki/node-static-alias/issues"},"license":"MIT","author":{"name":"anseki","url":"https://github.com/anseki"},"gitHead":"b0020219820a61094f34b545795ff5d9c15cdeef","_id":"node-static-alias@1.1.1","_npmVersion":"5.6.0","_nodeVersion":"8.11.1","_npmUser":{"name":"anseki","email":"AnSeki.aff@gmail.com"},"maintainers":[{"name":"anseki","email":""}],"dist":{"shasum":"38e70cf96c3014dabae9803e9da432de03878a49","size":11515,"noattachment":false,"key":"/node-static-alias/-/node-static-alias-1.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-static-alias/download/node-static-alias-1.1.1.tgz"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/node-static-alias_1.1.1_1527311826282_0.3439482252625554"},"_cnpmcore_publish_time":"2021-12-23T07:14:52.752Z","publish_time":1527311826407,"_cnpm_publish_time":1527311826407},"1.1.0":{"name":"node-static-alias","version":"1.1.0","title":"node-static-alias","description":"Serve static file which is not requested file. (e.g. `file.min.js` is requested, serve `file.js`)","keywords":["http","httpd","test","static","file","server","alias","mod_rewrite","directoryindex","min","log"],"main":"./lib/node-static-alias.js","files":["lib/!(.eslintrc.json)"],"engines":{"node":">= 0.8.0"},"dependencies":{"node-static":"~0.7.2"},"homepage":"https://github.com/anseki/node-static-alias","repository":{"type":"git","url":"git://github.com/anseki/node-static-alias.git"},"bugs":{"url":"https://github.com/anseki/node-static-alias/issues"},"license":"MIT","author":{"name":"anseki","url":"https://github.com/anseki"},"gitHead":"8432df11b60e0de67cbc7b7224470968c6729500","_id":"node-static-alias@1.1.0","_npmVersion":"5.6.0","_nodeVersion":"8.11.1","_npmUser":{"name":"anseki","email":"AnSeki.aff@gmail.com"},"maintainers":[{"name":"anseki","email":""}],"dist":{"shasum":"1cde7d7a44dd88713c9487cefa186418b35d3c24","size":5802,"noattachment":false,"key":"/node-static-alias/-/node-static-alias-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-static-alias/download/node-static-alias-1.1.0.tgz"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/node-static-alias_1.1.0_1527310546872_0.2891245164437579"},"_cnpmcore_publish_time":"2021-12-23T07:14:51.877Z","publish_time":1527310546934,"_cnpm_publish_time":1527310546934},"1.0.0":{"name":"node-static-alias","version":"1.0.0","title":"node-static-alias","description":"Serve static file which is not requested file. (e.g. `file.min.js` is requested, serve `file.js`)","keywords":["http","httpd","test","static","file","server","alias","mod_rewrite","directoryindex","min","log"],"main":"./lib/node-static-alias.js","engines":{"node":">= 0.8.0"},"dependencies":{"node-static":"~0.7.2"},"homepage":"https://github.com/anseki/node-static-alias","repository":{"type":"git","url":"git://github.com/anseki/node-static-alias.git"},"bugs":{"url":"https://github.com/anseki/node-static-alias/issues"},"license":"MIT","author":{"name":"anseki","url":"https://github.com/anseki"},"gitHead":"1aaae30213250d82ddb57f187db763313cc82c05","_id":"node-static-alias@1.0.0","scripts":{},"_shasum":"b12c63bbae51801c2619ded347976badd130733e","_from":".","_npmVersion":"3.10.9","_nodeVersion":"6.9.2","_npmUser":{"name":"anseki","email":"AnSeki.aff@gmail.com"},"maintainers":[{"name":"anseki","email":""}],"dist":{"shasum":"b12c63bbae51801c2619ded347976badd130733e","size":11152,"noattachment":false,"key":"/node-static-alias/-/node-static-alias-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-static-alias/download/node-static-alias-1.0.0.tgz"},"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/node-static-alias-1.0.0.tgz_1486120881273_0.7941532877739519"},"directories":{},"_cnpmcore_publish_time":"2021-12-23T07:14:51.007Z","publish_time":1486120881521,"_cnpm_publish_time":1486120881521},"0.1.3":{"name":"node-static-alias","version":"0.1.3","title":"node-static-alias","description":"Serve static file which is not requested file. (e.g. `file.min.js` is requested, serve `file.js`)","keywords":["http","httpd","test","static","file","server","alias","mod_rewrite","directoryindex","min","log"],"main":"./lib/node-static-alias.js","engines":{"node":">= 0.8.0"},"dependencies":{"node-static":"~0.7.2"},"homepage":"https://github.com/anseki/node-static-alias","repository":{"type":"git","url":"git://github.com/anseki/node-static-alias.git"},"bugs":{"url":"https://github.com/anseki/node-static-alias/issues"},"license":"MIT","author":{"name":"anseki","url":"https://github.com/anseki"},"gitHead":"d7b484009d53140b4f56a5f3df14d2de180a9aae","_id":"node-static-alias@0.1.3","scripts":{},"_shasum":"6088c0dfd06984d0e37bdf19ce489c4e3399997a","_from":".","_npmVersion":"1.4.28","_npmUser":{"name":"anseki","email":"AnSeki.aff@gmail.com"},"maintainers":[{"name":"anseki","email":""}],"dist":{"shasum":"6088c0dfd06984d0e37bdf19ce489c4e3399997a","size":11045,"noattachment":false,"key":"/node-static-alias/-/node-static-alias-0.1.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-static-alias/download/node-static-alias-0.1.3.tgz"},"directories":{},"_cnpmcore_publish_time":"2021-12-23T07:14:50.098Z","publish_time":1432793095312,"_cnpm_publish_time":1432793095312},"0.1.2":{"name":"node-static-alias","version":"0.1.2","title":"node-static-alias","description":"Serve static file which is not requested file. (e.g. `file.min.js` is requested, serve `file.js`)","keywords":["http","httpd","test","static","file","server","alias","mod_rewrite","directoryindex","min","log"],"main":"./lib/node-static-alias.js","engines":{"node":">= 0.8.0"},"dependencies":{"node-static":"~0.7.2"},"homepage":"https://github.com/anseki/node-static-alias","repository":{"type":"git","url":"git://github.com/anseki/node-static-alias.git"},"bugs":{"url":"https://github.com/anseki/node-static-alias/issues"},"licenses":"MIT","author":{"name":"anseki","url":"https://github.com/anseki"},"gitHead":"6d12fe11b0e7b335fd62decf3c6e681707f02748","_id":"node-static-alias@0.1.2","scripts":{},"_shasum":"b86956b92dd3f4291d35bd63af536b32224c3c04","_from":".","_npmVersion":"1.4.28","_npmUser":{"name":"anseki","email":"AnSeki.aff@gmail.com"},"maintainers":[{"name":"anseki","email":""}],"dist":{"shasum":"b86956b92dd3f4291d35bd63af536b32224c3c04","size":11071,"noattachment":false,"key":"/node-static-alias/-/node-static-alias-0.1.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-static-alias/download/node-static-alias-0.1.2.tgz"},"directories":{},"_cnpmcore_publish_time":"2021-12-23T07:14:49.226Z","publish_time":1414096136046,"_cnpm_publish_time":1414096136046},"0.1.1":{"name":"node-static-alias","description":"Serve static file which is not requested file. (e.g. `file.min.js` is requested, serve `file.js`)","version":"0.1.1","homepage":"https://github.com/anseki/node-static-alias","author":{"name":"anseki"},"repository":{"type":"git","url":"git://github.com/anseki/node-static-alias.git"},"bugs":{"url":"https://github.com/anseki/node-static-alias/issues"},"licenses":[{"type":"MIT","url":"https://github.com/anseki/node-static-alias/blob/master/LICENSE-MIT"}],"main":"./lib/node-static-alias.js","engines":{"node":">= 0.8.0"},"dependencies":{"node-static":"~0.7.2"},"keywords":["http","httpd","test","static","file","server","alias","mod_rewrite","directoryindex","min","log"],"_id":"node-static-alias@0.1.1","dist":{"shasum":"610e040e28311d9d82f660e94bdf38dfe7922ff0","size":11008,"noattachment":false,"key":"/node-static-alias/-/node-static-alias-0.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-static-alias/download/node-static-alias-0.1.1.tgz"},"_resolved":"c:\\DOCUME~1\\Admin\\LOCALS~1\\Temp\\npm-2456-MUj4KmL-\\1403826863811-0.8709786210674793\\tmp.tgz","_from":".","_npmVersion":"1.3.15","_npmUser":{"name":"anseki","email":"AnSeki.aff@gmail.com"},"maintainers":[{"name":"anseki","email":""}],"directories":{},"_cnpmcore_publish_time":"2021-12-23T07:14:48.347Z","publish_time":1403826823905,"_cnpm_publish_time":1403826823905},"0.1.0":{"name":"node-static-alias","description":"Serve static file which is not requested file. (e.g. `file.min.js` is requested, serve `file.js`)","version":"0.1.0","homepage":"https://github.com/anseki/node-static-alias","author":{"name":"anseki"},"repository":{"type":"git","url":"git://github.com/anseki/node-static-alias.git"},"bugs":{"url":"https://github.com/anseki/node-static-alias/issues"},"licenses":[{"type":"MIT","url":"https://github.com/anseki/node-static-alias/blob/master/LICENSE-MIT"}],"main":"./lib/node-static-alias.js","engines":{"node":">= 0.8.0"},"dependencies":{"node-static":"~0.7.2"},"keywords":["http","static","file","server","alias","mod_rewrite","directoryindex","min","log"],"_id":"node-static-alias@0.1.0","dist":{"shasum":"2c4419655178804c5c12cb542c03ba8ed58bf331","size":11003,"noattachment":false,"key":"/node-static-alias/-/node-static-alias-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-static-alias/download/node-static-alias-0.1.0.tgz"},"_resolved":"c:\\DOCUME~1\\Admin\\LOCALS~1\\Temp\\npm-2208-SRUwOQH9\\1388329065687-0.3270332692191005\\tmp.tgz","_from":".","_npmVersion":"1.3.15","_npmUser":{"name":"anseki","email":"AnSeki.aff@gmail.com"},"maintainers":[{"name":"anseki","email":""}],"directories":{},"_cnpmcore_publish_time":"2021-12-23T07:14:47.490Z","publish_time":1388329031309,"_cnpm_publish_time":1388329031309}},"readme":"# node-static-alias\n\n[![npm](https://img.shields.io/npm/v/node-static-alias.svg)](https://www.npmjs.com/package/node-static-alias) [![GitHub issues](https://img.shields.io/github/issues/anseki/node-static-alias.svg)](https://github.com/anseki/node-static-alias/issues) [![David](https://img.shields.io/david/anseki/node-static-alias.svg)](package.json) [![license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE-MIT)\n\nServe static file which is not requested file. (e.g. `file.min.js` is requested, serve `file.js`)  \nnode-static-alias wraps (inherits) the useful module [node-static](https://github.com/cloudhead/node-static/), and this adds the [`alias`](#alias) option to that.  \nThis works like the [Alias](http://httpd.apache.org/docs/2.4/mod/mod_alias.html) mapping or the [mod_rewrite\n](http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html) of Apache. It looks like [DirectoryIndex](http://httpd.apache.org/docs/2.4/mod/mod_dir.html#directoryindex) too. And this can check the file exists or not.\n\n+ Serve `file.js` instead of `file.min.js` which is not made yet, in the test phase.\n+ Serve the outside files of the document-root which are shared by multiple web sites in one machine.\n+ Serve the default page which is not `index.html` when *`/` is requested.\n\n## Synopsis\n\n```js\nvar staticAlias = require('node-static-alias');\n\n// Document-Root: './public' directory\nvar fileServer = new staticAlias.Server('./public', {\n  alias: {\n    match: '/path/to/file.min.js',\n    serve: '/path/to/file.js'\n  }\n});\n\nrequire('http').createServer(function(request, response) {\n  request.addListener('end', function() {\n    fileServer.serve(request, response);\n  }).resume();\n}).listen(8080);\n```\n\n## Usage\n\nThe [`alias`](#alias) option is added to the node-static via using `require('node-static-alias')` instead of `require('node-static')`. See [node-static](https://github.com/cloudhead/node-static/) to use it.\n\n### `alias`\n\nThe `alias` included in the constructor options is an Alias-Rule Object, or an array which includes multiple Alias-Rule Objects.\n\n```js\n  alias: {\n    match: /file\\.min\\.(?:js|css)$/,\n    serve: '/path/to/file.<% suffix %>'\n  }\n```\n\nOr\n\n```js\n  alias: [\n    {\n      match: '/path/to/file.min.js',\n      serve: '/path/to/file.js'\n    },\n    {\n      match: 'suffix=png',\n      serve: '../outer/<% fileName %>',\n      allowOutside: true\n    }\n  ]\n```\n\nThe Alias-Rule Object can have following properties.\n\n### `match`\n\n**Type:** string, RegExp, function or Array\n\nSpecify one of below or an Array which includes multiple things of those.  \nIf one or more things match, the [`serve`](#serve) is parsed. If anything doesn't match, it goes to next an Alias-Rule. If all Alias-Rules don't match, it tries to serve the requested file.\n\n+ **string:**  \nIf the requested path is equal to this string, it's matched.  \nOr, this can be `parameter=value` format (e.g. `suffix=png`). See [Parameters](#parameters). If the `value` is equal to the specified parameter, it's matched.\n\n```js\n  alias: [\n    {\n      match: '/path/to/file.min.js',\n      serve: '/path/to/file.js'\n    },\n    // Image files are not made yet.\n    {\n      match: 'suffix=png',\n      serve: '/path/to/dummy.png'\n    }\n  ]\n```\n\n+ **RegExp:**  \nThe RegExp which tests the requested path.\n\n```js\n  // These image files are not made yet.\n  alias: {\n    match: /\\/(?:foo|bar)\\.png$/,\n    serve: '/path/to/dummy.png'\n  }\n```\n\n+ **function:**  \nThe function which returns `true` or `false`.\nThe Object which has parameters is passed to this function. See [Parameters](#parameters). Also, current `request` instance and `response` instance are passed.  \nIn the function, `this` refers to own instance.\n\n```js\n  // Kick direct access from outside web site.\n  alias: {\n    match: function(params, request, response) {\n      console.log(request.url + ' was requested, in the path ' + this.root);\n      return params.suffix === 'jpg' &&\n        params.referer.indexOf('http://mysite.com/') !== 0;\n    },\n    serve: '/path/to/denial.jpg'\n  }\n```\n\n### `serve`\n\n**Type:** string, function or Array\n\nSpecify one of below or an Array which includes multiple things of those.  \nBy default, the first file which exists is chosen to try to serve. See [force](#force). If anything doesn't exist, it goes to next an Alias-Rule. If all files of Alias-Rules don't exist, it tries to serve the requested file.\n\n+ **string:**  \nThe absolute path or relative path from the document-root of the file to serve.  \nThis can include parameters like `<% parameter %>`. See [Parameters](#parameters).\n\n```js\n  // directoryIndex isn't index.html\n  alias: {\n    match: /\\/$/,\n    serve: '<% absPath %>/default.html'\n  }\n```\n\n*NOTE:* If the first character of this string is `/` (it might be parameter), this string is absolute path. This `/` doesn't point the document-root. It is the root of the local filesystem. If you want the relative path from the document-root, don't specify leading `/`, or add `.` to left of leading `/`.\n\n+ **function:**  \nThe function which returns the absolute path or relative path from the document-root of the file to serve.  \nThe Object which has parameters is passed to this function. See [Parameters](#parameters). Also, current `request` instance and `response` instance are passed.  \nIn the function, `this` refers to own instance.\n\n```js\n  // Minified files are not made yet.\n  alias: {\n    match: /\\.min\\.(?:js|css)$/,\n    serve: function(params, request, response) {\n      response.setHeader('X-serve-from', this.root);\n      return params.absDir + '/' +\n        params.basename.replace(/\\.min$/, '.') + params.suffix;\n    }\n  }\n```\n\n```js\n  // Compile unwatched SASS now.\n  alias: {\n    match: 'suffix=css',\n    serve: function(params) {\n      require('exec-sync')('sass ' +\n        params.absDir + '/' + params.basename + '.scss:' + params.absPath);\n      return params.absPath;\n    }\n  }\n```\n\n### `force`\n\n**Type:** boolean\n\nIf `true` is specified, the first file in the [`serve`](#serve) is chosen to try to serve without checking it's existing or not. And if it doesn't exist, a 404 error occurs. Default is `false`.  \nThis is used to prevent another file from being chosen unintentionally.\n\n### `allowOutside`\n\nIf `true` is specified, serving the outside files of the document-root is allowed. Default is `false`.\n\n```js\n  // Shared files.\n  alias: {\n    match: /^\\/common_lib/,\n    serve: '/path/to/lib/<% fileName %>',\n    allowOutside: true\n  }\n```\n\n*NOTE:* If you specify `true` in the public server, you should specify the absolute path to the [`serve`](#serve). Otherwise the user might access to the file that must be hidden from them.\n\n## Parameters\n\nThe string `parameter=value` can be specified to the [`match`](#match), and the string `<% parameter %>` can be specified to the [`serve`](#serve).  \nAnd also, the Object which has parameters is passed to function which specified to the [`match`](#match) and the [`serve`](#serve).  \nThese parameters are below.\n\n+ `reqUrl`  \nThe URL which is requested by the user. e.g. `/path/to/file.ext?key1=value1&key2=value2`\n+ `reqPath`  \nThe path which is requested by the user. e.g. `/path/to/file.ext`  \nThis might be a directory. e.g. `/`\n+ `reqDir`  \nThe path to a directory which is part of `reqPath`. e.g. `/path/to`\n+ `absPath`  \nThe absolute path to a requested file. e.g. `/var/www/public/path/to/file.ext`\n+ `absDir`  \nThe absolute path to a directory which is part of `absPath`. e.g. `/var/www/public/path/to`\n+ `fileName`  \nThe file name of a requested file. e.g. `file.ext`  \nThis might be a directory name e.g. `to`  \nIf the document-root is requested, this is empty string.\n+ `basename`  \nThe part of the file name except file-suffix. (`.` isn't included) e.g. `file`\n+ `suffix`  \nThe part of the file name which is extracted file-suffix. (`.` isn't included) e.g. `ext`\n+ `reqQuery`  \nThe URL query string which is part of `reqUrl`. e.g. `key1=value1&key2=value2`\n+ Parsed query string  \nPairs of a key beginning with a `query_` and a value. e.g. `query_key1`: `value1`, `query_key2`: `value2` from `reqQuery` above  \nAn array is extracted and each key is given `[INDEX]`. e.g. `query_key[0]`: `value1`, `query_key[1]`: `value2` from `key=value1&key=value2`\n+ Request Headers  \nThe HTTP Request Headers from the client. These are lower-cased. e.g. `referer`, `user-agent`, etc.\n\n## Logging\n\nThe `logger` included in constructor options is a Logger instance of the standard Logging Library (e.g. [log4js](https://github.com/nomiddlename/log4js-node)) which has `info` method or `log` method.\n\n```js\nvar log4js = require('log4js');\nvar logger = log4js.getLogger('node-static-alias');\nlogger.setLevel(log4js.levels.INFO);\n\nvar fileServer = new staticAlias.Server('./public' {\n  alias: { ... },\n  logger: logger\n});\n```\n\nYou can specify a simple Object which has `info` method or `log` method (e.g. `console` or `util`).  \nMost easy:\n\n```js\nvar fileServer = new staticAlias.Server('./public' {\n  alias: { ... },\n  logger: console\n  //logger: require('util') // Add timestamp\n});\n```\n\nAdd project name: (But, you probably use your favorite library.)\n\n```js\nvar fileServer = new staticAlias.Server('./public' {\n  alias: { ... },\n  logger: {log: function() {\n    var util = require('util');\n    console.log('[node-static-alias] ' +  util.format.apply(util, arguments));\n  }}\n});\n```\n\nLog message example:\n\n```console\n(/) Requested: \"/var/public\"\n(/file.min.css) Requested: \"/var/public/file.min.css\"\n(/file.min.css) For Serve: \"/var/public/file.css\" alias[3] match[1] serve[0]\n(/file.min.js) Requested: \"/var/public/file.min.js\"\n(/file.min.js) For Serve: \"/var/public/file.js\" alias[2] match[0] serve[1]\n```\n\nThe `(path)` is the path which is requested by the user. The `[number]` means an index of an Array.\n\n## Files list in the Directory\n\nThis example generates a list of files and directories in requested directory when the user accessed the directory. This works like the [mod_autoindex](http://httpd.apache.org/docs/2.4/mod/mod_autoindex.html) of Apache.\n\nThat looks like:  \n![ss](ss.png)\n\nThe [statsFilelist](https://www.npmjs.com/package/stats-filelist) is required.\n\n```\nnpm install stats-filelist\n```\n\nLoad that and some core modules.\n\n```js\nvar filelist = require('stats-filelist'),\n  path = require('path'),\n  fs = require('fs');\n```\n\nSpecify for `alias`:\n\n```js\nalias: {\n  match: function(params) {\n    try {\n      return fs.statSync(params.absPath).isDirectory();\n    } catch (error) {\n      return false; // Ignore \"Not found\" etc.\n    }\n  },\n  serve: function(params) {\n    var indexPath = path.join(params.absPath, '.index.html');\n    fs.writeFileSync(indexPath,\n      '<html><body><ul>' +\n      filelist.getSync(params.absPath, /^(?!.*[/\\\\]\\.index\\.html$).+$/, false)\n        .map(function(stat) {\n          var relPath = stat.name + (stat.isDirectory() ? '/' : '');\n          return '<li><a href=\"' + relPath + '\">' + relPath + '</a></li>';\n        }).join('') +\n      '</ul></body></html>');\n    return indexPath;\n  }\n}\n```\n","_attachments":{},"homepage":"https://github.com/anseki/node-static-alias","bugs":{"url":"https://github.com/anseki/node-static-alias/issues"},"license":"MIT"}