2015年7月30日 星期四

Nodejs

Core

-- Download node.js --

-- Download npm --

-- Download nodejs version manager for windows --


Commands to start

-- Install modules --

npm install _package_
npm install -g _package_ (globally instead of project folder only)

-- Run --

node _js_file
nodemon _js_file_ (require `npm install nodemon`)

Implementation samples


require('_moduel_or_file_name')
- as include

module.exports = function () {
  var service = {
    exposedMember: _privateMember
  }
  return service;
}
- to expose functions when required by other files

async module
- to simulate synchronized flow

2015年7月27日 星期一

Resume-able HTTP download (continuous downloading)

Required headers in the initial HTTP GET request

Range: (leave value empty to get Accept-Range type and ETag in response headers)

Required headers in the subsequent HTTP GET request

If-Range: [ETag]
Range: [type]=[start]-[end]
  • start from 0
  • end can be optional to retrieve to all
  • type can be bytes and all 

Response status

206 - Partial Content
200 - OK for the whole content in response body

Response headers

Content-Range: [type] [start]-[end]/[max]
  • max is the overall size of the file

Reference

http://stackoverflow.com/questions/8293687/sample-http-range-request-session
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.16
http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.12
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35