GithubHelp home page GithubHelp logo

adamhalasz / diet-static-stream Goto Github PK

View Code? Open in Web Editor NEW

This project forked from oscarr-reyes/diet-static-stream

0.0 2.0 0.0 15 KB

Serve static files through streaming objects for Diet.js

License: MIT License

JavaScript 100.00%

diet-static-stream's Introduction

diet-static-stream

Serve static files through streaming objects for Diet.js

Installation

$ npm install diet-static-stream

Usage

var diet = require("diet");
var dietStream = require("diet-static-stream");

var app = diet();

app.listen(80);

var static = dietStream({
	path: "static"
});

app.footer(static);

##Documentation Diet-static-stream can take several options for it's usage

path [String] - Required

Path where diet-static-stream will serve the files


index [String|Boolean] - Optional (Default: index)

Filename to look when there is no extension especified in the request

if value is Boolean, it will search for index file as default if true, otherwise if false, it will not do automatic search for an index file

#When value is boolean and it's true
GET: www.example.com/images -> Server/static/images/index.html

#When value is boolean and it's false
GET: www.example.com/images -> Server/static/images.html

#Otherwise if value is string, search for provided filename as index
#Value: main
GET: www.example.com/images -> Server/static/images/main.html

defaultExt [String] - Optional (Default: html)

Extension to look when there is no extension on the request

GET: www.example.com/images.html -> Server/static/images.html
GET: www.example.com/images -> Server/static/images.html OR Server/static/images/index.html according to index property

cache [String] - Optional (Default: max-age=3600)

Control-Cache value to set in header response


scriptName [Boolean] - Optional (Default: false)

Whether require extension file on the request, if true defaultExt and index options will be ignored

#Value: true
GET: www.example.com/images -> Server/static/images #404 not found
GET: www.example.com/images/user_placeholder.jpg -> Server/static/images/user_placeholder.jpg #200 Found

#Value: false
#Find according to index and defaultExt values
GET: www.example.com/images -> Server/static/images/index.html

F.A.Q

What is the difference between diet-static and this one?

The answer is simple, diet-static uses fs.readFile, and according to API docs of node.js it reads the entire contents of a file, meaning that all the data from a file is temporary stored in the memory, this is nice if you only read few files with small sizes.

But what happens when you use it on a server that has hundreds of requests for media files, this could lead the server to overload and crash.

This package uses stream objects for sending chunks of data when they are being on read, this does not load data into the memory and we can avoid memory overload for hundreds of requests

##License MIT

diet-static-stream's People

Contributors

oscarr-reyes avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.