Skip to content

docs: update examples to ES6 #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install serve-static
## API

```js
var serveStatic = require('serve-static')
const serveStatic = require('serve-static')
```

### serveStatic(root, options)
Expand Down Expand Up @@ -132,15 +132,15 @@ the arguments are:
### Serve files with vanilla node.js http server

```js
var finalhandler = require('finalhandler')
var http = require('http')
var serveStatic = require('serve-static')
const finalhandler = require('finalhandler')
const http = require('http')
const serveStatic = require('serve-static')

// Serve up public/ftp folder
var serve = serveStatic('public/ftp', { index: ['index.html', 'index.htm'] })
const serve = serveStatic('public/ftp', { index: ['index.html', 'index.htm'] })

// Create server
var server = http.createServer(function onRequest (req, res) {
const server = http.createServer((req, res) => {
serve(req, res, finalhandler(req, res))
})

Expand All @@ -151,13 +151,13 @@ server.listen(3000)
### Serve all files as downloads

```js
var contentDisposition = require('content-disposition')
var finalhandler = require('finalhandler')
var http = require('http')
var serveStatic = require('serve-static')
const contentDisposition = require('content-disposition')
const finalhandler = require('finalhandler')
const http = require('http')
const serveStatic = require('serve-static')

// Serve up public/ftp folder
var serve = serveStatic('public/ftp', {
const serve = serveStatic('public/ftp', {
index: false,
setHeaders: setHeaders
})
Expand All @@ -168,7 +168,7 @@ function setHeaders (res, path) {
}

// Create server
var server = http.createServer(function onRequest (req, res) {
const server = http.createServer((req, res) => {
serve(req, res, finalhandler(req, res))
})

Expand All @@ -183,10 +183,10 @@ server.listen(3000)
This is a simple example of using Express.

```js
var express = require('express')
var serveStatic = require('serve-static')
const express = require('express')
const serveStatic = require('serve-static')

var app = express()
const app = express()

app.use(serveStatic('public/ftp', { index: ['default.html', 'default.htm'] }))
app.listen(3000)
Expand All @@ -199,11 +199,11 @@ Files are searched for in `public-optimized/` first, then `public/` second
as a fallback.

```js
var express = require('express')
var path = require('path')
var serveStatic = require('serve-static')
const express = require('express')
const path = require('path')
const serveStatic = require('serve-static')

var app = express()
const app = express()

app.use(serveStatic(path.join(__dirname, 'public-optimized')))
app.use(serveStatic(path.join(__dirname, 'public')))
Expand All @@ -217,11 +217,11 @@ file. In this example, HTML files are not cached, while everything else
is for 1 day.

```js
var express = require('express')
var path = require('path')
var serveStatic = require('serve-static')
const express = require('express')
const path = require('path')
const serveStatic = require('serve-static')

var app = express()
const app = express()

app.use(serveStatic(path.join(__dirname, 'public'), {
maxAge: '1d',
Expand Down