expressjs.com
expressjs.com copied to clipboard
deno support
express.json() middleware doesn't work when using with deno
@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);
}
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.