First the index.js
var mongoose = require('mongoose');
var express = require('express');
var router = express.Router();
router.post('/adduser', function (req, res) {
var db = require("../db");
var userName = req.body.username;
var userEmail = req.body.useremail;
var Users = db.Mongoose.model('usercollection', db.UserSchema, 'usercollection');
var user = new Users({ username: userName, email: userEmail });
user.save(function (err) {
if (err) {
console.log("Error! " + err.message);
return err;
}
else {
console.log("Post saved");
res.send("Feito");
}
});
});
Then the HTML div that inserts
<div>
<h1 class="text-center title-1"> Cadastro de Usuário </h1>
<form action="/adduser" method="post">
<p>Username:<input type="text" name="username" /></p>
<p>Email:<input type="text" name="useremail" /></p>
<p><input type="submit" value="Salvar" class="button_active" ></p>
</form>
</div>
Now below I will post my attempt to display a user
First the .js
router.get('/showuser', function (req, res) {
var db = require("../db");
var userName = req.body.username;
var cursor = db.usercollection.find({'username': userName});
cursor.save(function (err) {
if (err) {
console.log("Error! " + err.message);
return err;
}
else {
console.log("Post saved");
res.send("Feito");
}
});
});
Then HTML
<form action="/showuser" method="get">
<p>Username:<input type="text" name="username" /></p>
<p><input type="submit" value="Salvar" class="button_active" ></p>
</form>
The browser displays this
I would like some light on how to perform this procedure to display a user from a table using HTML