Skip to content

Instantly share code, notes, and snippets.

@SimiCode
Created Feb 11, 2019
Embed
What would you like to do?
node_js_loop
// doing check when array is empty produces non stopping loop
// add database
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var json2html = require('node-json2html');
var app = express();
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
app.set('view engine', 'pug');
app.set('views','./views');
var builders = [];
app.get('/check', function(req, res) {
return res.render('check');
});
app.post('/check', function(req, res) {
// res.setHeader('Content-Type', 'application/json');
var contact = req.body.contact;
var arrayLength = builders.length;
for (var i = 0; i < arrayLength; i++) {
if (builders[i].contact==contact){
// if (builders[i].includes(contact)){
builder = builders[i];
var name = builder.name;
var contact = builder.contact;
var pledged = builder.pledged;
var paid = builder.paid;
return res.render('checked', { name: name, contact: contact, pledged: pledged, paid: paid } );
} else {
// res.render('check');
// res.redirect(req.get('referer'));
};
return res.send("Not Found!");
// res.send(builder);
// res.send(JSON.stringify({'builder': builder}));
}});
app.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment