title: How to make user registration with Node.js and MongoDB (using mongoose and Express.js)
body: <p>I need your help. I want to make User registration form and use Nodejs, Express.js, MongoDB(mongoose) and give me very simple example how to make user registration form with: Name, Email, Password and Mobile Number :) I've made mongoose schema and give values like that Name: req.body.name but it won't work :/ In my oppinion I made something bad.</p>
  
  <p>this is my code and if you think it's not correct, please correct it. (sorry for my bad english). this is server.js</p>
  
  <pre><code>var mongoose = require('mongoose');
  mongoose.connect('mongodb://localhost/addressbookdb');
  var express = require('express');
  var app = express();
  var db = mongoose.connection;
  
  app.use(express.static(__dirname + '/../client'));
  
  app.post("/",function(req,res){
      res.end("Registration Succesfully Completed!");
  
      var db = mongoose.connection;
      db.on('error', console.error.bind(console, 'connection error:'));
      db.once('open', function (callback) {
          console.log("connected.")
      });
  
      // Schema
      var RegSchema = mongoose.Schema({
          Name: String,
          Email: String,
          Pass: String,
          Num: Number,
          reg_time : {
              type : Date, default: Date.now
          }
      }, { collection: 'AddressCol' });
  
      // Model
      var UserReg = mongoose.model('UserReg', RegSchema);
  
      // Add in collection
      var UserAdd = new UserReg({
          Name: req.body.name,
          Email: req.body.email,
          Pass: req.body.pass,
          Num: req.body.num,
      });
  
      // Save
      UserAdd.save(function (err, fluffy) {
          if (err) return console.error(err);
      });
  });
  
  app.listen(8000, function() {
    console.log("Server is running!");
  });
  </code></pre>
  
  <p>and this is my HTML page: </p>
  
  <pre><code>&lt;div class="form-group"&gt;
      &lt;input type="text" class="form-control" id="name" placeholder="name&gt;&lt;br&gt;
      &lt;input type="email" class="form-control" id="email" placeholder="Email"&gt;&lt;br&gt;
      &lt;input type="password" class="form-control" id="pass" placeholder="Password"&gt;&lt;br&gt;
      &lt;input type="number" class="form-control" id="num" placeholder="Number"&gt;&lt;br&gt;
      &lt;button type="submit" class="btn btn-primary" id="reg-form-btn"&gt;Registration!&lt;/button&gt;
  &lt;/div&gt;
  &lt;script&gt;
      $(document).ready(function() {
          $("#reg-form-btn").click(function() {
              var name = $("#name").val();
              var email = $("#email").val();
              var pass = $("#pass").val();
              var num = $("#num").val();
              $.post("/", {
                  Name: name,
                  Email: email,
                  Pass: pass,
                  Num: num
              });
          });
      });
  &lt;/script&gt;
  </code></pre>