expressjs.com icon indicating copy to clipboard operation
expressjs.com copied to clipboard

deno support

Open topperspal opened this issue 2 years ago • 1 comments

express.json() middleware doesn't work when using with deno

topperspal avatar Apr 04 '23 00:04 topperspal

@topperspal you can try this approach

import { serve } from "https://deno.land/std/http/server.ts";
import { bodyParser } from "https://deno.land/x/oak/mod.ts";

const server = serve({ port: 3000 });

const app = new Oak();

// Apply the bodyParser middleware to parse JSON request bodies
app.use(bodyParser());

// Define your routes and handle the parsed request body
app.post("/example", async (ctx) => {
  const body = await ctx.request.body({ type: "json" }).value;
  // Access the parsed JSON body using `body` variable
  console.log(body);

  // Handle the request and send a response
  ctx.response.body = "Request received!";
});

for await (const req of server) {
  app.handle(req);
}

shaad00 avatar Jun 12 '23 07:06 shaad00

This is not an issue with the Express documentation, and seems more like a feature request any way. If you want to pursue this, please open an issue in https://github.com/expressjs/express.

crandmck avatar Apr 29 '24 21:04 crandmck