raunioroo
raunioroo
DDeno
Created by Inke on 2/18/2025 in #help
how do I access post data in a deno http server?
Well, I remember all this was surprisingly hard/painful to figure out, since there are so many different ways to POST, and all needed to be handled in a different way, wasn't that obvious :)
14 replies
DDeno
Created by Inke on 2/18/2025 in #help
how do I access post data in a deno http server?
...and for detecting which one to use:
const contentType = request.headers.get("content-type");
if (contentType == "application/x-www-form-urlencoded") {
// url encoded
} else if (contentType.includes("multipart/form-data")) {
// multipart
} else if (contentType == "application/json") {
// json
}
const contentType = request.headers.get("content-type");
if (contentType == "application/x-www-form-urlencoded") {
// url encoded
} else if (contentType.includes("multipart/form-data")) {
// multipart
} else if (contentType == "application/json") {
// json
}
14 replies
DDeno
Created by Inke on 2/18/2025 in #help
how do I access post data in a deno http server?
For multipart post:
const formData = await request.formData();
const entries = {};
for (const [key, value] of formData) {
entries[key] = value;
}
return entries;
const formData = await request.formData();
const entries = {};
for (const [key, value] of formData) {
entries[key] = value;
}
return entries;
14 replies
DDeno
Created by Inke on 2/18/2025 in #help
how do I access post data in a deno http server?
For raw json:
const postdata = await request.text();
return JSON.parse(postdata);
const postdata = await request.text();
return JSON.parse(postdata);
14 replies
DDeno
Created by Inke on 2/18/2025 in #help
how do I access post data in a deno http server?
For URL encoded post data (like your curl call seems to be), I use this:
const postdata = await request.text();
// console.log("POSTDATA", postdata);
const searchParams = new URLSearchParams(postdata);
const post = {};
for (const [key, value] of searchParams.entries()) {
// console.log("FOUND", key, value)
post[key] = value;
}
const postdata = await request.text();
// console.log("POSTDATA", postdata);
const searchParams = new URLSearchParams(postdata);
const post = {};
for (const [key, value] of searchParams.entries()) {
// console.log("FOUND", key, value)
post[key] = value;
}
14 replies
DDeno
Created by Akash on 2/10/2025 in #help
Is it a good idea to use Deno edge functions as a websocket server?
The 50ms limit is pure CPU time; waiting for IO, network and stuff is not counted towards that limit. I don't know if it can be calulated and/or how that applies to longer websocket connections since the limits are "per request" so is over the whole connection time or what. Hopefully someone else with more deploy experience can chime in.
5 replies
DDeno
Created by Akash on 2/10/2025 in #help
Is it a good idea to use Deno edge functions as a websocket server?
Deploy functions are "short lived", so you can't count on them having any particular lifetime. To my knowledge, in practice the typical lifetime is somewhere between minutes up to an hour or so (?). So you need to design your app in a way that it can easily reconnect to another instance, and assume connections are short-lived (or rather "medium-lived" compared to some other edge services). I think it should be doable given those limitations.
5 replies
DDeno
Created by raunioroo on 2/26/2024 in #help
Deny env permissions silently (without throwing)
nice! good to know I can now remove the hairy workarounds!
9 replies
DDeno
Created by Oxooxo on 1/28/2025 in #help
How to get problems solved
Denos approach is super cool, but it is so hard to transfer simple things from node to deno.
First, a disclaimer - I'm not completely certain what DTO's are, or even Reflection in this context, just a hunch. But anyway: Looking at your two open posts, they don't look particularly simple transfers though. Reflection and GYP related things seem to me like pretty involved stuff that are heavily linked with node internals. Deno's node compatibility is great as long as you are dealing with relatively straightforward javascript libraries. But when you (or the libraries or frameworks you use) start fiddling with native code, reflection, custom module loaders and other stuff meddling with node internals like that you are bound to run into problems. I don't even comment on the added complexity or potential for interoperability bugs typescript brings to the table. Many NPM modules do really weird node-specific stuff, and it could be asked, if one actually need that stuff, maybe one should the real thing (node) then. Because there are limits how far Deno can, or maybe even should take the node compatibility. It's like, people seem to have a lot of problems with Deno and Vite - and Vite to me seem like exactly the type of system that does a lot of unorthodox things under the hood, or assumes a lot of things are implemented in a particular way to make the magic happen. This makes 100% compatibility a very much non-trivial thing to accomplish. Sorry if this is not much help! Just an observation! The types of questions you asked, I'm not that surprised no one has been able to give easy answers, is all. Not sure if there are any better channels to ask. Folks tend to be pretty helpful here at least when the questions can be answered with relatively little effort or the solutions are "common knowledge"!
4 replies
DDeno
Created by Diaz Kautsar on 12/20/2024 in #help
Issue with Adding Object to S3 from Deno Deploy (Works Locally)
Hi! I'm not too familiar with deploy, or aws-sdk. But I have had success using https://deno.land/x/s3@0.5.0 as a simple, lightweight library for S3. IIRC aws-sdk was at least unnecessarily huge. Can't remember if that was the reason I ditched the official aws-sdk, or was it not working with deno for some reason. Either way, the mentioned library has served me well.
3 replies
DDeno
Created by nounderline on 12/2/2024 in #help
How to exclude code and imports from deno compile binary?
I would think having 2 entrypoints like leokuma said, would be the "right" way. Deno only bundles the files that are actually used/imported beginning from the entrypoint module. One could say it's treeshaking at the file level, not invidual export level, and if the code/dependencies is properly organized, that's all the "treeshaking" you need. If your modules import a bunch of unneeded stuff, you might want to look into how you do import dependencies in general, you might be doing something wrong (or at least suboptimally). Common mistake is to use deps.ts approach to specify dependencies. That indeed tends to cause a bunch of unneeded code being loaded/included in the graph. Better to use import maps, which won't actually load the modules unless they are actually, directly used/imported by the entrypoint or it's dependencies. In any case, Deno compile binaries will always be very large, since they contain an almost complete version of deno + your code.
11 replies
DDeno
Created by yoggyd on 9/4/2024 in #help
any reason against using the deps.ts approach?
Not sure if I understand the question, but will reply anyway :) Annoyingly, JSR import paths look very different to deno.land style plain URL imports, in that they start different and end different. This means you can't just set up a prefix like "@std" in the import map, and easily switch between JSR and something else by editing the import map only. So, you need to set up and map full aliases for each possible import to be able to switch repositories or use local filesystem copy, without touching the actual import statements in code.
7 replies
DDeno
Created by yoggyd on 9/4/2024 in #help
any reason against using the deps.ts approach?
Third downside is with deps.ts will cause all referenced libraries to be loaded and initialized whether they are used or not by the main entrypoint. If using dynamic imports that problem can be amplified. With import maps you can reference as many libraries as you like, and they will only be loaded on-demand.
7 replies
DDeno
Created by Parallax on 7/9/2024 in #help
Is there a way to use Javascript as easily as Php?
VPS servers are a nice, cheap middleground between administering your own server, and ready made cloud solutions. A bit more involved in setup than your typical php service,but not too bad. Cheapest option in AWS Lightsail is around 5 bucks a month, and works great with deno (unless your app is a memory hog, in which case you should look into the more expensive options with more RAM)
40 replies
DDeno
Created by thailephan on 5/20/2024 in #help
Are there any up-to-date library for date and time in Deno?
Date and time libraries seem to be somewhat inactive since JS standard Temporal API is just around the corner, and will have/has most features you'd ever need built in. And in fact usable in Deno with - - unstable-temporal. Meanwhile, there is simple but useful and up to date https://jsr.io/@std/datetime , and like you mention could bring stuff from npm. Temporal is pretty nice though, if you are ok with using unstable stuff
3 replies
DDeno
Created by Phatso on 5/10/2024 in #help
Websockets API with async processing (is there a better way?)
Someone correct if I'm wrong, but I think worker comms involve some internal serialization under the hood (some relative of structuredClone?). Which would be faster than JSON, but slower than not reserializing. So I'd think it's probably a little faster to just send the string to the worker and parse the JSON there. Which makes sense also in that if you are using multiple workers to distribute load, you'd want to move as much processing to the workers as possible, keeping the main process as lightweight as possible (since every request goes through that single threaded "load balancer", you want to avoid it becoming a bottleneck).
12 replies
DDeno
Created by Phatso on 5/10/2024 in #help
Websockets API with async processing (is there a better way?)
Also, not sure if it applies to websockets app like yours, but I do some heavy image processing in thread pool of sorts, and found the optimal number of processing threads to be number_of_cores - 1. I assume it's because if I saturate ALL the cores completely with image processing, the various other system threads or processes may get bogged down also then everything can become a bit unresponsive. But if I always have 1 semi-idle core, the system always has a place to execute background stuff on, resulting in smoother overall performance and even if slightly less "images per second", the performance "per image" is more consistent and predictable.
12 replies
DDeno
Created by Phatso on 5/10/2024 in #help
Websockets API with async processing (is there a better way?)
Just a thought: Could each worker have a standalone websocket server, just on their own ports? Clients would connect directly to own worker port, assigned somehow to balance workload to the number of cores. This would negate the need for all connections to go through the main process/thread, as well as negate redundant message serialization & deserialization between workers and the main process (JSON.parse and I assume passing messages to workers involve some semi-expensive IPC-like message serialization under the hood).
12 replies
DDeno
Created by bebraw on 4/28/2024 in #help
How to abstract tests to allow running different functions against the same test suite?
Nothing public sry. But basically something along the lines of
// --------------- testsuite.js
import * as sharedTest_A from "./sharedtest_A.js";

Deno.test({
name: "testFoo",
fn: async (t) => {
await t.step("sharedTest_A", async (t) => {
await sharedTest_A.testFoo(t);
await sharedTest_A.testBar(t);
});
// await t.step("sharedtest_B" async (t) => { ... });
}
})

// --------------- sharedtest_A.js
export async function testFoo(t) {
await t.step("test 1", async (t) => {
// do something
});
await t.step("test 2", async (t) => {
// do something
});
}
export async function testBar(t) {
await t.step("test 3", async (t) => {
// do something
});
await t.step("test 4", async (t) => {
// do something
});

}
// --------------- testsuite.js
import * as sharedTest_A from "./sharedtest_A.js";

Deno.test({
name: "testFoo",
fn: async (t) => {
await t.step("sharedTest_A", async (t) => {
await sharedTest_A.testFoo(t);
await sharedTest_A.testBar(t);
});
// await t.step("sharedtest_B" async (t) => { ... });
}
})

// --------------- sharedtest_A.js
export async function testFoo(t) {
await t.step("test 1", async (t) => {
// do something
});
await t.step("test 2", async (t) => {
// do something
});
}
export async function testBar(t) {
await t.step("test 3", async (t) => {
// do something
});
await t.step("test 4", async (t) => {
// do something
});

}
Passing t around is needed for proper nesting of steps in the output.'
5 replies
DDeno
Created by bebraw on 4/28/2024 in #help
How to abstract tests to allow running different functions against the same test suite?
I mean, for some reason I used to think test files are some special, limited dialect of JS. Once I realized it is just normal code which can be organized to modules, classes, functions, exports, imports like any other app, it suddenly felt like I gained testing superpowers.
5 replies