0

In my application, I have a form with the action pointing to a nodejs endpoint. It is sucessfully performing the action, but when i try to extract the posted data from req, it refuses to give me anything. I may just be looking in the wrong place.

Here is my HTML

<body>
    <h1>Hello, you are here</h1>
    <form action="/archive_message" method="post">
        Message URL: <input type="text" name="urlToProcess">
        <select>
            <option name="process-method" value="msg">Message</option>
            <option name="process-method" value="trd">Thread</option>
            <option name="process-method" value="act">Account</option>
        </select>
        <input type = "submit" value = "Submit">
    </form>
</body>

here is my js

server.start().then(res => {
   server.applyMiddleware({app})
   app.listen(8081, function () {   
      console.log("Running!");
   })
});


app.get('/', function (req, res) {
   res.sendFile( __dirname + "/" + "index.html");
   console.log("200 - GET");
});


app.post('/archive_message', function (req, res) {
   console.log(req.body.urlToProcess);
   res.redirect("/");
})

When i log req.body, i just get header info, when i try to dig further, i get errors. How am i supposed to be accessing the data submitted by the form?

specifically, i am getting this error: TypeError: Cannot read properties of undefined (reading 'urlToProcess')

Any help is appreciated.

1 Answers1

-1

try this one app.use(express.urlencoded({ extended: true }));