I have looked at all similar questions and none are working for me. I have a node js app in which I cannot print the input text from a form, using body-parser.
My index.ejs:
<form id="demo-2" method = "POST" action="/search">
<input type="search" name = "searcher" placeholder="Search">
</form>
Index.js:
var cool = require('cool-ascii-faces');
var express = require('express');
var app = express();
var pg = require('pg');
var bodyParser = require('body-parser');
var env = require('node-env-file');
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/views/'));
// views is directory for all template files
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
//app.use(express.bodyParser());
//DIFFERENT APPS - tells them what to do
app.post('/search', function(request, response) {
//var username = req.body;
console.log("posted something"+ request.body.searcher);
response.end("something was posted: "+ request.body.searcher);
});
app.get('/search', function(request, response) {
response.send("skylarr");
});
And despite using the input's name searcher I get error: TypeError: Cannot read property 'searcher' of undefined
What is wrong here?