How to do forms in ExpressJs?

I’m trying to make a form with Node.js/Express and I need help! It’s a simple form that asks the user for their name and message and puts it in a database (Replit’s db).

There is no code link or Repl link because I haven’t started it yet.

1 Like

expressjs isn’t able to do forms directly (it can’t do anything client-side), although it can handle form submissions

2 Likes

It can if u are creative about it

1 Like

What you probably want to do is receive a post request:

// automatically turn all form/json input to json
express.use(express.json());

// simple post route
app.post("/api", function(req, res) {
	// print the form/json input
	console.log(req.body);
});

I’m not 100% sure about form input being automatically converted to JSON, so you should test this to be sure.

2 Likes

Can I invite you to the Repl I’m working on so you can understand?

Sure that’s fine :+1:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.