Skip to content

Instantly share code, notes, and snippets.

@nomoney4me
Last active November 18, 2018 00:05
Show Gist options
  • Select an option

  • Save nomoney4me/52c81677ca6c88e75f3cd8b3afd98ce2 to your computer and use it in GitHub Desktop.

Select an option

Save nomoney4me/52c81677ca6c88e75f3cd8b3afd98ce2 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
var ws = new WebSocket("ws://localhost:3001/ws");
ws.onmessage = function(msg) {
console.log(msg)
}
</script>
</body>
</html>
const express = require('express')
, app = express()
, experssWs = require('express-ws')(app)
app.use(express.static(__dirname + '/client'))
app.ws('/ws', (ws, req) => {
setInterval(() => {
ws.send('hi')
}, 1000)
})
app.listen(3001, console.log(`listening on 3001`))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment