https://www.youtube.com/watch?v=JnvKXcSI7yk
I got an error at 1:08:22
Code for creating a database
extend layout
block content
h1 Add new Contact
form(method="POST", action="/new_contact")
p Name:
input#title(type="text",name="name")
p Phone No.:
input#title(type="text",name="phone")
p: button(type="submit") Add new Contact
h1 Add new Database
form(method="POST", action="/createdb")
p Database name:
input#title(type="text",name="dbname")
p: button(type="submit") Add new Database
h1 enter Phone number to delete new_contact
form(method="POST", action="/delete_contact")
p Phone No.:
input#title(type="text",name="phone")
p: button(type="submit") Delete Contact
h1 View specific contact
form(method="POST", action="/view_contact")
p Phone No.:
input#title(type="text",name="phone")
p: button(type="submit") Search Contact
code of app.js
//dependencies we are using
var express = require("express");
var routes = require("./routes");
var http = require("http");
var urlencode = require("url");
var path = require("path");
var bodyParser = require("body-parser");
var json = require("json");
var logger = require("log");
var methodOverride = require("method-override");
var nano = require("nano")("http://localhost:5984"); //address of couchdb server
var db = nano.use("address");
var app = express();
//Environment
app.set("port", process.env.PORT || 3000);
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "jade");
//App using all imported modules
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(methodOverride());
app.use(express.static(path.join(__dirname, "public")));
//for creating databases
app.get("/", routes.index);
app.post("/createdb", function (req, res) {
nano.db.create(req.body.dbname, function (err) {
if (err) {
res.send("Error creating database" + req.body.dbname);
return;
}
res.send("Database" + req.body.dbname + "created successfully");
});
});
//for new_contact we are creating
app.post("/new_contact", function (req, res) {
var name = req.body.name;
var phone = req.body.phone;
db.insert(
{
name: name,
phone: phone,
crazy: true,
},
phone,
function (err, body, header) {
if (err) {
res.send("Error in creating Contact");
return;
}
res.send("contact created successfully");
}
);
});
//To view contact
app.post("/view_contact", function (req, res) {
var alldocs = "following are the contact";
db.get(
req.body.phone,
{
revs_info: true,
},
function (err, body) {
if (!err) {
console.log(body);
}
if (body) {
alldocs += "Name:" + body.name + "<br/>Phon Number:" + body.phone;
} else {
alldocs = "No records found";
}
res.send(alldocs);
}
);
});
//to delete contact
app.post("/delete_contact", function (req, res) {
db.get(
req.body.phone,
{
revs_info: true,
},
function (err, body) {
if (!err) {
db.destroy(req.body.phone, body._rev, function (err, body) {
if (err) {
res.send("Error deleting contact");
}
});
res.send("contact deleted successfully");
}
}
);
});
//creating server
http.createServer(app).listen(app.get("port"), function () {
console.log("Express server listening on port " + app.get("port"));
});
please help as I'm new to nodejs and expressjs.