Last active
January 18, 2020 22:35
-
-
Save tsh-code/fd4fa1d1609a861f78cddd7a5e57b385 to your computer and use it in GitHub Desktop.
Simple WebSocket Api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const WebSocket = require("ws"); | |
const wss = new WebSocket.Server({ port: 8080 }); | |
const mockedUsers = [ | |
{ | |
id: 1, | |
firstname: "John", | |
lastname: "Doe" | |
} | |
]; | |
wss.on("connection", ws => { | |
ws.on("message", data => { | |
const message = JSON.parse(data); | |
if (message.type === "get-users") { | |
ws.send(JSON.stringify(mockedUsers)); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment