Socket
Socket
Sign inDemoInstall

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.


Version published
Weekly downloads
473K
decreased by-0.23%
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 21 Jul 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