Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

server-timestamp

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

server-timestamp

Create a middleware to add a server timestamp header in milliseconds. Use for Express

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

server-timestamp

NPM Version NPM Downloads

Create a middleware to add a server timestamp header in milliseconds. Use for Express

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install --save server-timestamp

API

var serverTimestamp = require('server-timestamp');

serverTimestamp([options])

Create a middleware that adds a X-Server-Timestamp header to responses. If you don't want to use this module to automatically set a header, please see the section about Options format

Options

The serverTimestamp function accepts an optional options object that may contain any of the following keys:

header

The name of the header to set, defaults to X-Server-Timestamp.

format

This is a function that formats timestamps.

Examples

default

var serverTimestamp = require('./');
var express = require('express');
var app = express();

app.use(serverTimestamp());

// response
app.get('/', function (req, res) {
    /*
     res results:

       {
         "x-powered-by": "Express",
         "x-server-timestamp": 1493365865576
       }
     */
    res.send(res._headers)
});

app.listen(3000, function () {
    console.log('Example app listening on port 3000!')
});

set header

var serverTimestamp = require('./');
var express = require('express');
var app = express();

app.use(serverTimestamp({header: 'Example-Server-Timestamp'}));

// response
app.get('/', function (req, res) {
    /*
     res results:

       {
         "x-powered-by": "Express",
         "example-server-timestamp": 1493365865576
       }
     */
    res.send(res._headers)
});

app.listen(3000, function () {
    console.log('Example app listening on port 3000!')
});

set header and format

var serverTimestamp = require('./');
var express = require('express');
var app = express();

app.use(serverTimestamp({
    header: 'Example-Format-Server-Timestamp',
    format: function(timestamp){
        var now = new Date(timestamp);
        var year = now.getFullYear();
        var month = now.getMonth() + 1;
        var date = now.getDate();
        var hour = now.getHours();
        var minute = now.getMinutes();
        var second = now.getSeconds();

        return year + '-' + month + '-' + date + ' '+ hour + ':' + minute + ':' + second;
    }
}));

// response
app.get('/', function (req, res) {
    /*
     res results:

       {
         "x-powered-by": "Express",
         "example-format-server-timestamp": "2017-4-28 15:51:5"
       }
     */
    res.send(res._headers)
});

app.listen(3000, function () {
    console.log('Example app listening on port 3000!')
});

Full Example

Check this repo for full example with Express.

License

MIT

Keywords

FAQs

Package last updated on 28 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc