Websocket basic Authorisation in Node.js

Secure websockets, authenticated with Basic http authentication.

On the client-side they throw a popup and you provide it with an username and a password to authenticate yourself and gain access.

On the server-side you have to add this to your request headers.

There are a lot of websocket client packages available on npm, but they don’t have easy access to the request headers.

We extended the nodejs-websocket package with this extra feature.

This way, we could add Basic access authentication headers to our project through the extraHeaders property in options.


var ws = require('nodejs-websocket')

var name = 'test'

var password = 'test123'

var options = {

	extraHeaders: {

  // implementation of Basic access authentication 

		Authorization: 'Basic ' + new Buffer(name+ ':' + password).toString('base64')



var conn = ws.connect('wss://data.appsaloon.io/socket',options)