thevan thevan - 5 months ago 92
Node.js Question

How to get textbox value in node.js file?

This is my html code:

<form id="fileupload" method="POST" enctype="multipart/form-data">

<div class="row fileupload-buttonbar">
<textarea name="txtFolderName" rows="1"></textarea>
<button type="create" class="btn btn-primary start">
<i class="glyphicon glyphicon-upload"></i>
<span>Create Folder</span>
</button>
</div>


When I click the "Create Folder" button, I will do some function based on the textbox value. How to get the textbox value to the node.js file during POST method?

Answer

For express you can use bodyParser() middleware (https://github.com/expressjs/body-parser) and get submited fields from req.body.

var express    = require('express');
var bodyParser = require('body-parser');

var app = express();
app.use(bodyParser());

app.post('/uploaded',function(req, res, next){
    var txt_folder_name = req.body.txtFolderName;
    //...
});