NDH
NDH
DDeno
Created by Inke on 2/18/2025 in #help
how do I access post data in a deno http server?
if ("POST" === req.method) {
if (req.body) return new Response(JSON.parse(await req.text()),{ status: 200 })
}
if ("POST" === req.method) {
if (req.body) return new Response(JSON.parse(await req.text()),{ status: 200 })
}
14 replies
DDeno
Created by ©TriMoon™ on 1/31/2025 in #help
Help setting up a Deno project for a static HTML5 app using TypeScript and a Live-preview.
12 replies
DDeno
Created by ©TriMoon™ on 1/31/2025 in #help
Help setting up a Deno project for a static HTML5 app using TypeScript and a Live-preview.
12 replies
DDeno
Created by $e.bash-tian on 1/28/2025 in #help
Deno application with just a Websocket connection gives 504 in Prod Deno Deploy
That is normal Deploy isolate operation. An isolate can be expected to stop at anytime usually around 5 or 6 minutes. They are not expected to last longer without an explicitly active connection; not the WebSocket that it initiated, but the connection that you made when you started it in Deploy. That initial connection is no longer active after you start it.
If you make a browser-app with an EventSource connection(SSE), the server will maintain the stream connection, and if not, this browser-app will reestablish the connection automatically. You would only need to run the app once as a starter/maintainer. Good-Luck!
86 replies
DDeno
Created by $e.bash-tian on 1/28/2025 in #help
Deno application with just a Websocket connection gives 504 in Prod Deno Deploy
Quick questions!
How do you start the Deploy service?
How would you ping that service?
86 replies
DDeno
Created by $e.bash-tian on 1/28/2025 in #help
Deno application with just a Websocket connection gives 504 in Prod Deno Deploy
You could setup an SSE connection from your client to the Deploy service. These tend to auto-reconnect the server (isolate) if it goes to sleep. This would work as long as you're not holding any state in the Deploy service. When the isolate drops, the client will auto-connect in a second or two. No pings required. I have some experience with this if you need. https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#closing_event_streams
By default, if the connection between the client and server closes, the connection is restarted.
By default, if the connection between the client and server closes, the connection is restarted.
That is, the client will auto-reconnect!
And, the docs also state:
Note: The comment line can be used to prevent connections from timing out; a server can send a comment periodically to keep the connection alive.
Note: The comment line can be used to prevent connections from timing out; a server can send a comment periodically to keep the connection alive.
Below, the server should attempt to keep itself alive to deliver the stream!
And, if not, the client will attempt to auto-reconnect (continuously).
Deno -> server-side:
async function* sse() {
while (true) { // every minute you send a comment line
await new Promise(r => setTimeout(r, 60000));
yield ': comments are ignored by the client \n\n';
}
}

router.get('/sse', contentType(['text/event-stream']), (req, { type }) => {
return new StreamResponse(sse(), { headers: [['content-type', type]] })
})
async function* sse() {
while (true) { // every minute you send a comment line
await new Promise(r => setTimeout(r, 60000));
yield ': comments are ignored by the client \n\n';
}
}

router.get('/sse', contentType(['text/event-stream']), (req, { type }) => {
return new StreamResponse(sse(), { headers: [['content-type', type]] })
})
86 replies
DDeno
Created by kaltcium on 1/4/2025 in #help
Newbie question: Web development in Deno 2, and .ts to .js transpiling.
When your ready, grab a copy and examine it. It is pretty straight forward, and perhaps you could make a custom copy for you're own use.
5 replies
DDeno
Created by kaltcium on 1/4/2025 in #help
Newbie question: Web development in Deno 2, and .ts to .js transpiling.
The reason I built Hot, is that I don't care for all the bloat that a tool like Vite adds to your project.
Hot does not require any deno.json, nor any package.json, and no node-modules folder. Hot creates its own config file on first use, and that is its only requirement.
The goal was to create an environment for quick development of vanilla HTML, CSS, JavaScript applications that leverage the joy of coding with Typescript.
5 replies
DDeno
Created by kaltcium on 1/4/2025 in #help
Newbie question: Web development in Deno 2, and .ts to .js transpiling.
I built my own dev server. Think Mini-Vite! Have a look: https://jsr.io/@ndh/hot
5 replies
DDeno
Created by Jasmine Boba'tea on 1/3/2025 in #help
What is the best way to get the full url that Deno.serve() is running on?
Logging info on Windows returns an empty object?
ServeHandlerInfo {}
ServeHandlerInfo {}
With either console.log(info) or, console.info(info)?
6 replies
DDeno
Created by Jasmine Boba'tea on 1/3/2025 in #help
What is the best way to get the full url that Deno.serve() is running on?
You can also get it from the request:
Deno.serve({ port: 1993, hostname: '0.0.0.0'},
(request: Request) => {
const url = new URL(request.url)
return new Response(`
Hello From:
origin = ${url.origin}
host = ${url.host}
hostname = ${url.hostname}
port = ${url.port}
transport protocol = ${url.protocol}:
`)
})
Deno.serve({ port: 1993, hostname: '0.0.0.0'},
(request: Request) => {
const url = new URL(request.url)
return new Response(`
Hello From:
origin = ${url.origin}
host = ${url.host}
hostname = ${url.hostname}
port = ${url.port}
transport protocol = ${url.protocol}:
`)
})
I'm on Widows where 0.0.0.0 === localhost.
Hello From:
origin = http://localhost:1993
host = localhost:1993
hostname = localhost
port = 1993
transport protocol = http:
Hello From:
origin = http://localhost:1993
host = localhost:1993
hostname = localhost
port = 1993
transport protocol = http:
If I then open 127.0.0.2 :1993 as expected:
Hello From:
origin = http://127.0.0.2:1993
host = 127.0.0.2:1993
hostname = 127.0.0.2
port = 1993
transport protocol = http:
Hello From:
origin = http://127.0.0.2:1993
host = 127.0.0.2:1993
hostname = 127.0.0.2
port = 1993
transport protocol = http:
6 replies
DDeno
Created by scarf on 12/25/2024 in #help
std JSON serializer/deserializer with Set and Map support
It would be very hard to beat the performance of native V8 JSON! Native V8 JSON is extremely fast
Type User = {id: number, first: string, last: string, age: number}>

// pre-fill with 100k user objects
const userMap: Map<number, User> = new Map()

// Serialize the Map
// 100k objects(10.7 MB) takes ~ 90ms.
let serializedUsers = JSON.stringify(Array.from(userMap.entries()))

/* Deserialize
* hydrating 100,000 user objects takes ~ 160ms :
* JSON.Parse: 145.30ms
* Build-Map: 16.80ms
*/
const deserializedUsers = JSON.parse(serializedUsers)
userMap = new Map(deserializedUsers)
Type User = {id: number, first: string, last: string, age: number}>

// pre-fill with 100k user objects
const userMap: Map<number, User> = new Map()

// Serialize the Map
// 100k objects(10.7 MB) takes ~ 90ms.
let serializedUsers = JSON.stringify(Array.from(userMap.entries()))

/* Deserialize
* hydrating 100,000 user objects takes ~ 160ms :
* JSON.Parse: 145.30ms
* Build-Map: 16.80ms
*/
const deserializedUsers = JSON.parse(serializedUsers)
userMap = new Map(deserializedUsers)
See this in action : https://nhrones.github.io/Hot_BuenoCache/ NOTE: First use builds a test dataset in IndexedDB. Run more than once. Repo at: https://github.com/nhrones/Hot_BuenoCache
6 replies
DDeno
Created by avem on 12/3/2024 in #help
Worried about cold start
Kv as server-side local-first See : https://zero.rocicorp.dev/
12 replies
DDeno
Created by avem on 12/3/2024 in #help
Worried about cold start
Kv as server-side local-first
12 replies
DDeno
Created by Robbie on 11/28/2024 in #help
Replacing `fs.createWriteStream()` with Deno equivalent
Naming is hard 😣
9 replies
DDeno
Created by Bruno Skvorc on 11/27/2024 in #help
Without using a framework, how do I compile natively supported TS in Deno into static JS?
For a working example see: https://nhrones.github.io/Hot_BuenoCache/ Click the see-the-code link on the bottom left of the page!
Or just go to the repo:
https://github.com/nhrones/Hot_BuenoCache
6 replies
DDeno
Created by Bruno Skvorc on 11/27/2024 in #help
Without using a framework, how do I compile natively supported TS in Deno into static JS?
You could try a simple util like https://jsr.io/@ndh/build Or, even better; roll-your-own! Create the following module -- builder.ts
import { denoPlugins } from "jsr:@luca/esbuild-deno-loader@^0.11.0";
import { build, stop } from "npm:esbuild@0.24.0";

/** builds and bundles an entrypoint into a single ESM output. */
export async function buildIt() {
await build({
plugins: [...denoPlugins({})],
entryPoints: ["./src/main.ts"],
outfile: "./dist/bundle.js",
bundle: true,
minify: false,
keepNames: true,
banner: { js: `// @ts-nocheck
// deno-lint-ignore-file`},
format: "esm"
}).catch((e: Error) => console.info(e));
stop();
}

buildIt()
console.log('bundle.js was built!')
import { denoPlugins } from "jsr:@luca/esbuild-deno-loader@^0.11.0";
import { build, stop } from "npm:esbuild@0.24.0";

/** builds and bundles an entrypoint into a single ESM output. */
export async function buildIt() {
await build({
plugins: [...denoPlugins({})],
entryPoints: ["./src/main.ts"],
outfile: "./dist/bundle.js",
bundle: true,
minify: false,
keepNames: true,
banner: { js: `// @ts-nocheck
// deno-lint-ignore-file`},
format: "esm"
}).catch((e: Error) => console.info(e));
stop();
}

buildIt()
console.log('bundle.js was built!')
Just modify the entrypoints and outfile to suit your needs. You can also specify to bundle or not, and minification or not. Add the above module to you project root. Then just to run:
deno run -A --quiet builder.ts
You could also add this as a task in deno.json called build.
6 replies
DDeno
Created by artpods56 on 11/17/2024 in #help
Cant configure Tailwind with DaisyUI using Deno inside of Docker | Error: Cannot find module daisyui
This is great info, and will help me in the future. Thanks for this.
13 replies
DDeno
Created by Kevin Tale on 11/22/2024 in #help
How to add a simple live reload?
30 replies
DDeno
Created by Kevin Tale on 11/25/2024 in #help
cannot publish package to jsr but it uses a shared file
There is a new Discord server for JSR
https://discord.gg/hMqvhAn9xG. Perhaps you could get help there.
3 replies