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

hsts

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hsts

HTTP Strict Transport Security middleware.

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
217K
decreased by-54.52%
Maintainers
1
Weekly downloads
 
Created

What is hsts?

The 'hsts' npm package is used to set the HTTP Strict Transport Security (HSTS) header in web applications. This header is used to enforce secure (HTTP over SSL/TLS) connections to the server.

What are hsts's main functionalities?

Basic HSTS Header Setup

This code sets up a basic Express server and uses the 'hsts' middleware to set the HSTS header with a max age of 1 year (31536000 seconds).

const hsts = require('hsts');
const express = require('express');
const app = express();

app.use(hsts({ maxAge: 31536000 })); // 1 year in seconds

app.get('/', (req, res) => {
  res.send('Hello, world!');
});

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

HSTS with Subdomains

This code sets the HSTS header to include subdomains by setting the 'includeSubDomains' option to true.

const hsts = require('hsts');
const express = require('express');
const app = express();

app.use(hsts({ maxAge: 31536000, includeSubDomains: true }));

app.get('/', (req, res) => {
  res.send('Hello, world!');
});

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

HSTS with Preload

This code sets the HSTS header with the 'preload' option, which allows the domain to be included in browsers' HSTS preload lists.

const hsts = require('hsts');
const express = require('express');
const app = express();

app.use(hsts({ maxAge: 31536000, preload: true }));

app.get('/', (req, res) => {
  res.send('Hello, world!');
});

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Other packages similar to hsts

Keywords

FAQs

Package last updated on 22 Sep 2015

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