title: how to connect html page with nodejs
body: <p>Iam not able to get the html page.My nodejs is connecting with mongodb but when iam getting values from html page the values are not storing in db.Iam not able establish the connection from frontend to db at a time.help me out</p>
  
  <p>this is my login.html</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;login&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form action="/" method="POST"&gt;
  &lt;center&gt;
  User Name: &lt;input type="text" name="username"&gt; &lt;br&gt;
  Password: &lt;input type="password" name="password"&gt;&lt;br&gt;
  &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and this is my login.js code</p>
  
  <pre><code>var express = require('express');
  
       var app = express();
  
       var mongoose = require('mongoose');
  
       var url = 'mongodb://localhost:27017/logindb';
  
       var loginSchema = mongoose.Schema({
          username: String,
          password: String
       });
  
       mongoose.connect(url);
  
       app.get('/login.html', function(req, res) {
          res.sendFile(__dirname + "/" + "login.html");
       })
  
       app.post('/', function(req, res) {
  
          var Book = mongoose.model('book', loginSchema);
  
          var book1 = new Book({
              username: req.body.username,
              password: req.body.password
          });
          book1.save(function(err) {
              if (err) throw err;
              console.log("Login saved succesfully");
              res.end('success');
          }
          );
       });
  
       app.listen(8000, function() {
          console.log("Server is running!");
       });
  </code></pre>