Deno is a simple, modern and secure runtime for JavaScript and TypeScript that uses V8 and is built in Rust.
This is a Deno fork that modifies the WebSocket interface to support the same functionality as WebsocketStream but preserving the Websocket interface's stability
const socket = new WebSocket("wss:https://ws.postman-echo.com/raw", {
protocols: ["custom-protocol"],
headers: {
origin: "https://example.com",
cookie: `custom_cookie=here`,
},
});
// then you would just use the WebSocket api like normal.
socket.addEventListener("open", (event) => {
socket.send("Hello Server!");
});
socket.addEventListener("message", function (event) {
console.log("Message from server ", event.data);
});
socket.addEventListener("close", (event) => {
console.log("The connection has been closed successfully.");
});
socket.addEventListener("error", function (event) {
console.log("WebSocket error: ", event);
});
- Secure by default. No file, network, or environment access, unless explicitly enabled.
- Supports TypeScript out of the box.
- Ships only a single executable file.
- Built-in utilities.
- Set of reviewed standard modules that are guaranteed to work with Deno.
Shell (Mac, Linux):
curl -fsSL https://deno.land/install.sh | sh
PowerShell (Windows):
irm https://deno.land/install.ps1 | iex
Homebrew (Mac):
brew install deno
Chocolatey (Windows):
choco install deno
Scoop (Windows):
scoop install deno
Build and install from source using Cargo:
cargo install deno --locked
See deno_install and releases for other options.
Try running a simple program:
deno run https://deno.land/std/examples/welcome.ts
Or a more complex one:
const listener = Deno.listen({ port: 8000 });
console.log("http:https://localhost:8000/");
for await (const conn of listener) {
serve(conn);
}
async function serve(conn: Deno.Conn) {
for await (const { respondWith } of Deno.serveHttp(conn)) {
respondWith(new Response("Hello world"));
}
}
You can find a deeper introduction, examples, and environment setup guides in the manual.
The complete API reference is available at the runtime documentation.
We appreciate your help!
To contribute, please read our contributing instructions.