'selectedHandler' is not a function, Node JS











up vote
1
down vote

favorite












I am a newbie with Node JS and i recently made all the APIs which are working exactly as i want. However, now i want some of them (example handler.home) to return a static html template also. But, now i am getting an error as below....



Server.js



const config = require('../config');

//Dependencies
const http = require('http');
const https = require('https');
//file system support to read files
var fs = require('fs');
//path module to access directories
var path = require('path');
var url = require('url');

//importing the handlers
var handlers = require('./handlers');

//importing helpers
var helpers = require('./helpers');

var stringDecoder = require('string_decoder').StringDecoder;


//server object to handle all the tasks
let server = {}

//creating a server from the https module which defines what to do when the server is created
server.httpsServerOptions = {
'key': fs.readFileSync(path.join(__dirname, '/../https/key-pem')),
'cert': fs.readFileSync(path.join(__dirname, '/../https/cert.pem'))
};

//creating a server from the http module which defines what to do when the server is created
server.httpServer = http.createServer(function(req, res){
server.unifiedServer(req, res);
});

server.httpsServer = https.createServer(server.httpsServerOptions, function(req, res){
server.unifiedServer(req, res);
});

server.unifiedServer = function(req,res){
//steps of parsing a user request

//GET the method of request -> get/put/delete/post
var method = req.method.toLowerCase();
//PARSE THE URL / get the url
var parsedUrl = url.parse(req.url, true);
var path = parsedUrl.pathname;
var queryObject = parsedUrl.query;
var trimmedPath = path.replace(/^/+|/+$/g, '');

//Read Headers
var urlHeaders = req.headers;

var decoder = new stringDecoder('utf-8');
var bufferPayload = '';

//event handler when some data is recieved in the payload / body
req.on('data', (data) => {

bufferPayload += decoder.write(data);
});

req.on('end', () => {
bufferPayload += decoder.end();

//ROUTE TO A SPECIFIC HANDLER BASED ON ROUTING OBJECT, ROUTE TO NOTFOUND IF NOT FOUND
var selectedHandler = typeof(server.router[trimmedPath]) !== 'undefined' ? handlers[trimmedPath] : handlers.notFound;
//once the handler is specified, we need to send some data to it as expected by the handler
var data = {
'headers': urlHeaders,
'method': method,
'pathname': trimmedPath,
'payload': helpers.convertJSONstr2JSON(bufferPayload),
'queryString': queryObject
}
//send the data and look for callback
selectedHandler(data, (statusCode, payload, contentType) => {
console.log("entered")
//send a default status code of 200 if no status code is defined
statusCode = typeof(statusCode) == 'number' ? statusCode : 200;
//set contentType to json if no contentType is provided for rendering
contentType = typeof(contentType) == 'string' ? contentType : 'json';
if(contentType == 'json'){
res.setHeader('Content-Type', 'application/json');
payload = typeof(payload) == 'object' ? JSON.stringify(payload) : JSON.stringify({});
}
if (contentType == 'html'){
res.setHeader('Content-Type', 'text/html');
payload = typeof(payload) == 'string' ? payload : '';
}
res.writeHead(statusCode);

//SEND THE RESPOSE FROM THE SERVER
res.end(payload);

//LOG IF YOU NEED TO THE CONSOLE
if(statusCode == 200){
//display in green
console.log('x1b[32m%sx1b[0m',"response on ", method +" " +trimmedPath, " ->", statusCode);
}
else {
//for any non 200 status, display in red
console.log('x1b[31m%sx1b[0m',"response on ", method +" " +trimmedPath, " ->", statusCode);
}
});
});
};

server.router = {
'' : handlers.home,
'account/create': handlers.accountCreate,
'account/edit': handlers.accountEdit,
'account/deleted': handlers.accountDeleted,
'session/create' : handlers.sessionCreate,
'session/deleted' : handlers.sessionDeleted,
'checks/create' : handlers.checksCreate,
'checks/all': handlers.checkList,
'checks/edit': handlers.checksEdit,
'ping': handlers.ping,
'api/users': handlers.users,
'api/tokens': handlers.tokens,
'api/checks': handlers.checks
};

//intitialise the server file
server.init = ()=>{

server.httpServer.listen(config.httpPort, function(){
console.log('x1b[36m%sx1b[0m',"the server is listening on port "+config.httpPort + " ["+config.envName+"] ");
});

server.httpsServer.listen(config.httpsPort, function(){
console.log('x1b[35m%sx1b[0m',"the server is listening on port "+config.httpsPort + " ["+config.envName+"] ");
});
};

module.exports = server;


handlers.js



/*
*This file stores all the handlers
*
*/


//dependencies
let dataLib = require('./data');
let helpers = require('./helpers');
let config = require('../config');

//main code
let handlers = {};

/*
* HTML API HANDLERS BELOW
*
*/

handlers.home = function(data, callback){
console.log("found index ->", data);
callback(200, 'undefined', 'html');
};
module.exports = handlers;


And the error that i am recieving is
enter image description here



Now what i want is to be able to respond if the contentType is html, which is not working right now. If i don't provide the contentType and set the behavior of the api to return json, everything works fine. Any ideas?










share|improve this question




















  • 1




    My first thought before looking at your code is to spell handler correctly if your title is anything to go by. Also helpers.convertJSONstr2JSON - there is a native function called JSON.parse for this?
    – Dominic
    Nov 19 at 17:14












  • lol sorry, mistyped it :p
    – rishabh kalra
    Nov 19 at 17:15










  • Are you exporting your handlers in handlers.js like so module.exports = handlers?
    – dotconnor
    Nov 19 at 17:17










  • Please, don't post your code/error messages as images. Firstly we want to copy/paste it and secondly search engines are unable to index that information. So please make sure that any textual information is actually provided in text form.
    – lucascaro
    Nov 19 at 17:18










  • There isn't enough information here to tell what the problem is. You have var selectedHandler = typeof(server.router[trimmedPath]) !== 'undefined' ? handlers[trimmedPath] : handlers.notFound; so start your debugging to figure out which of the ternary options is being picked. Then figure out why it isn't the value you expect.
    – Quentin
    Nov 19 at 17:18















up vote
1
down vote

favorite












I am a newbie with Node JS and i recently made all the APIs which are working exactly as i want. However, now i want some of them (example handler.home) to return a static html template also. But, now i am getting an error as below....



Server.js



const config = require('../config');

//Dependencies
const http = require('http');
const https = require('https');
//file system support to read files
var fs = require('fs');
//path module to access directories
var path = require('path');
var url = require('url');

//importing the handlers
var handlers = require('./handlers');

//importing helpers
var helpers = require('./helpers');

var stringDecoder = require('string_decoder').StringDecoder;


//server object to handle all the tasks
let server = {}

//creating a server from the https module which defines what to do when the server is created
server.httpsServerOptions = {
'key': fs.readFileSync(path.join(__dirname, '/../https/key-pem')),
'cert': fs.readFileSync(path.join(__dirname, '/../https/cert.pem'))
};

//creating a server from the http module which defines what to do when the server is created
server.httpServer = http.createServer(function(req, res){
server.unifiedServer(req, res);
});

server.httpsServer = https.createServer(server.httpsServerOptions, function(req, res){
server.unifiedServer(req, res);
});

server.unifiedServer = function(req,res){
//steps of parsing a user request

//GET the method of request -> get/put/delete/post
var method = req.method.toLowerCase();
//PARSE THE URL / get the url
var parsedUrl = url.parse(req.url, true);
var path = parsedUrl.pathname;
var queryObject = parsedUrl.query;
var trimmedPath = path.replace(/^/+|/+$/g, '');

//Read Headers
var urlHeaders = req.headers;

var decoder = new stringDecoder('utf-8');
var bufferPayload = '';

//event handler when some data is recieved in the payload / body
req.on('data', (data) => {

bufferPayload += decoder.write(data);
});

req.on('end', () => {
bufferPayload += decoder.end();

//ROUTE TO A SPECIFIC HANDLER BASED ON ROUTING OBJECT, ROUTE TO NOTFOUND IF NOT FOUND
var selectedHandler = typeof(server.router[trimmedPath]) !== 'undefined' ? handlers[trimmedPath] : handlers.notFound;
//once the handler is specified, we need to send some data to it as expected by the handler
var data = {
'headers': urlHeaders,
'method': method,
'pathname': trimmedPath,
'payload': helpers.convertJSONstr2JSON(bufferPayload),
'queryString': queryObject
}
//send the data and look for callback
selectedHandler(data, (statusCode, payload, contentType) => {
console.log("entered")
//send a default status code of 200 if no status code is defined
statusCode = typeof(statusCode) == 'number' ? statusCode : 200;
//set contentType to json if no contentType is provided for rendering
contentType = typeof(contentType) == 'string' ? contentType : 'json';
if(contentType == 'json'){
res.setHeader('Content-Type', 'application/json');
payload = typeof(payload) == 'object' ? JSON.stringify(payload) : JSON.stringify({});
}
if (contentType == 'html'){
res.setHeader('Content-Type', 'text/html');
payload = typeof(payload) == 'string' ? payload : '';
}
res.writeHead(statusCode);

//SEND THE RESPOSE FROM THE SERVER
res.end(payload);

//LOG IF YOU NEED TO THE CONSOLE
if(statusCode == 200){
//display in green
console.log('x1b[32m%sx1b[0m',"response on ", method +" " +trimmedPath, " ->", statusCode);
}
else {
//for any non 200 status, display in red
console.log('x1b[31m%sx1b[0m',"response on ", method +" " +trimmedPath, " ->", statusCode);
}
});
});
};

server.router = {
'' : handlers.home,
'account/create': handlers.accountCreate,
'account/edit': handlers.accountEdit,
'account/deleted': handlers.accountDeleted,
'session/create' : handlers.sessionCreate,
'session/deleted' : handlers.sessionDeleted,
'checks/create' : handlers.checksCreate,
'checks/all': handlers.checkList,
'checks/edit': handlers.checksEdit,
'ping': handlers.ping,
'api/users': handlers.users,
'api/tokens': handlers.tokens,
'api/checks': handlers.checks
};

//intitialise the server file
server.init = ()=>{

server.httpServer.listen(config.httpPort, function(){
console.log('x1b[36m%sx1b[0m',"the server is listening on port "+config.httpPort + " ["+config.envName+"] ");
});

server.httpsServer.listen(config.httpsPort, function(){
console.log('x1b[35m%sx1b[0m',"the server is listening on port "+config.httpsPort + " ["+config.envName+"] ");
});
};

module.exports = server;


handlers.js



/*
*This file stores all the handlers
*
*/


//dependencies
let dataLib = require('./data');
let helpers = require('./helpers');
let config = require('../config');

//main code
let handlers = {};

/*
* HTML API HANDLERS BELOW
*
*/

handlers.home = function(data, callback){
console.log("found index ->", data);
callback(200, 'undefined', 'html');
};
module.exports = handlers;


And the error that i am recieving is
enter image description here



Now what i want is to be able to respond if the contentType is html, which is not working right now. If i don't provide the contentType and set the behavior of the api to return json, everything works fine. Any ideas?










share|improve this question




















  • 1




    My first thought before looking at your code is to spell handler correctly if your title is anything to go by. Also helpers.convertJSONstr2JSON - there is a native function called JSON.parse for this?
    – Dominic
    Nov 19 at 17:14












  • lol sorry, mistyped it :p
    – rishabh kalra
    Nov 19 at 17:15










  • Are you exporting your handlers in handlers.js like so module.exports = handlers?
    – dotconnor
    Nov 19 at 17:17










  • Please, don't post your code/error messages as images. Firstly we want to copy/paste it and secondly search engines are unable to index that information. So please make sure that any textual information is actually provided in text form.
    – lucascaro
    Nov 19 at 17:18










  • There isn't enough information here to tell what the problem is. You have var selectedHandler = typeof(server.router[trimmedPath]) !== 'undefined' ? handlers[trimmedPath] : handlers.notFound; so start your debugging to figure out which of the ternary options is being picked. Then figure out why it isn't the value you expect.
    – Quentin
    Nov 19 at 17:18













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am a newbie with Node JS and i recently made all the APIs which are working exactly as i want. However, now i want some of them (example handler.home) to return a static html template also. But, now i am getting an error as below....



Server.js



const config = require('../config');

//Dependencies
const http = require('http');
const https = require('https');
//file system support to read files
var fs = require('fs');
//path module to access directories
var path = require('path');
var url = require('url');

//importing the handlers
var handlers = require('./handlers');

//importing helpers
var helpers = require('./helpers');

var stringDecoder = require('string_decoder').StringDecoder;


//server object to handle all the tasks
let server = {}

//creating a server from the https module which defines what to do when the server is created
server.httpsServerOptions = {
'key': fs.readFileSync(path.join(__dirname, '/../https/key-pem')),
'cert': fs.readFileSync(path.join(__dirname, '/../https/cert.pem'))
};

//creating a server from the http module which defines what to do when the server is created
server.httpServer = http.createServer(function(req, res){
server.unifiedServer(req, res);
});

server.httpsServer = https.createServer(server.httpsServerOptions, function(req, res){
server.unifiedServer(req, res);
});

server.unifiedServer = function(req,res){
//steps of parsing a user request

//GET the method of request -> get/put/delete/post
var method = req.method.toLowerCase();
//PARSE THE URL / get the url
var parsedUrl = url.parse(req.url, true);
var path = parsedUrl.pathname;
var queryObject = parsedUrl.query;
var trimmedPath = path.replace(/^/+|/+$/g, '');

//Read Headers
var urlHeaders = req.headers;

var decoder = new stringDecoder('utf-8');
var bufferPayload = '';

//event handler when some data is recieved in the payload / body
req.on('data', (data) => {

bufferPayload += decoder.write(data);
});

req.on('end', () => {
bufferPayload += decoder.end();

//ROUTE TO A SPECIFIC HANDLER BASED ON ROUTING OBJECT, ROUTE TO NOTFOUND IF NOT FOUND
var selectedHandler = typeof(server.router[trimmedPath]) !== 'undefined' ? handlers[trimmedPath] : handlers.notFound;
//once the handler is specified, we need to send some data to it as expected by the handler
var data = {
'headers': urlHeaders,
'method': method,
'pathname': trimmedPath,
'payload': helpers.convertJSONstr2JSON(bufferPayload),
'queryString': queryObject
}
//send the data and look for callback
selectedHandler(data, (statusCode, payload, contentType) => {
console.log("entered")
//send a default status code of 200 if no status code is defined
statusCode = typeof(statusCode) == 'number' ? statusCode : 200;
//set contentType to json if no contentType is provided for rendering
contentType = typeof(contentType) == 'string' ? contentType : 'json';
if(contentType == 'json'){
res.setHeader('Content-Type', 'application/json');
payload = typeof(payload) == 'object' ? JSON.stringify(payload) : JSON.stringify({});
}
if (contentType == 'html'){
res.setHeader('Content-Type', 'text/html');
payload = typeof(payload) == 'string' ? payload : '';
}
res.writeHead(statusCode);

//SEND THE RESPOSE FROM THE SERVER
res.end(payload);

//LOG IF YOU NEED TO THE CONSOLE
if(statusCode == 200){
//display in green
console.log('x1b[32m%sx1b[0m',"response on ", method +" " +trimmedPath, " ->", statusCode);
}
else {
//for any non 200 status, display in red
console.log('x1b[31m%sx1b[0m',"response on ", method +" " +trimmedPath, " ->", statusCode);
}
});
});
};

server.router = {
'' : handlers.home,
'account/create': handlers.accountCreate,
'account/edit': handlers.accountEdit,
'account/deleted': handlers.accountDeleted,
'session/create' : handlers.sessionCreate,
'session/deleted' : handlers.sessionDeleted,
'checks/create' : handlers.checksCreate,
'checks/all': handlers.checkList,
'checks/edit': handlers.checksEdit,
'ping': handlers.ping,
'api/users': handlers.users,
'api/tokens': handlers.tokens,
'api/checks': handlers.checks
};

//intitialise the server file
server.init = ()=>{

server.httpServer.listen(config.httpPort, function(){
console.log('x1b[36m%sx1b[0m',"the server is listening on port "+config.httpPort + " ["+config.envName+"] ");
});

server.httpsServer.listen(config.httpsPort, function(){
console.log('x1b[35m%sx1b[0m',"the server is listening on port "+config.httpsPort + " ["+config.envName+"] ");
});
};

module.exports = server;


handlers.js



/*
*This file stores all the handlers
*
*/


//dependencies
let dataLib = require('./data');
let helpers = require('./helpers');
let config = require('../config');

//main code
let handlers = {};

/*
* HTML API HANDLERS BELOW
*
*/

handlers.home = function(data, callback){
console.log("found index ->", data);
callback(200, 'undefined', 'html');
};
module.exports = handlers;


And the error that i am recieving is
enter image description here



Now what i want is to be able to respond if the contentType is html, which is not working right now. If i don't provide the contentType and set the behavior of the api to return json, everything works fine. Any ideas?










share|improve this question















I am a newbie with Node JS and i recently made all the APIs which are working exactly as i want. However, now i want some of them (example handler.home) to return a static html template also. But, now i am getting an error as below....



Server.js



const config = require('../config');

//Dependencies
const http = require('http');
const https = require('https');
//file system support to read files
var fs = require('fs');
//path module to access directories
var path = require('path');
var url = require('url');

//importing the handlers
var handlers = require('./handlers');

//importing helpers
var helpers = require('./helpers');

var stringDecoder = require('string_decoder').StringDecoder;


//server object to handle all the tasks
let server = {}

//creating a server from the https module which defines what to do when the server is created
server.httpsServerOptions = {
'key': fs.readFileSync(path.join(__dirname, '/../https/key-pem')),
'cert': fs.readFileSync(path.join(__dirname, '/../https/cert.pem'))
};

//creating a server from the http module which defines what to do when the server is created
server.httpServer = http.createServer(function(req, res){
server.unifiedServer(req, res);
});

server.httpsServer = https.createServer(server.httpsServerOptions, function(req, res){
server.unifiedServer(req, res);
});

server.unifiedServer = function(req,res){
//steps of parsing a user request

//GET the method of request -> get/put/delete/post
var method = req.method.toLowerCase();
//PARSE THE URL / get the url
var parsedUrl = url.parse(req.url, true);
var path = parsedUrl.pathname;
var queryObject = parsedUrl.query;
var trimmedPath = path.replace(/^/+|/+$/g, '');

//Read Headers
var urlHeaders = req.headers;

var decoder = new stringDecoder('utf-8');
var bufferPayload = '';

//event handler when some data is recieved in the payload / body
req.on('data', (data) => {

bufferPayload += decoder.write(data);
});

req.on('end', () => {
bufferPayload += decoder.end();

//ROUTE TO A SPECIFIC HANDLER BASED ON ROUTING OBJECT, ROUTE TO NOTFOUND IF NOT FOUND
var selectedHandler = typeof(server.router[trimmedPath]) !== 'undefined' ? handlers[trimmedPath] : handlers.notFound;
//once the handler is specified, we need to send some data to it as expected by the handler
var data = {
'headers': urlHeaders,
'method': method,
'pathname': trimmedPath,
'payload': helpers.convertJSONstr2JSON(bufferPayload),
'queryString': queryObject
}
//send the data and look for callback
selectedHandler(data, (statusCode, payload, contentType) => {
console.log("entered")
//send a default status code of 200 if no status code is defined
statusCode = typeof(statusCode) == 'number' ? statusCode : 200;
//set contentType to json if no contentType is provided for rendering
contentType = typeof(contentType) == 'string' ? contentType : 'json';
if(contentType == 'json'){
res.setHeader('Content-Type', 'application/json');
payload = typeof(payload) == 'object' ? JSON.stringify(payload) : JSON.stringify({});
}
if (contentType == 'html'){
res.setHeader('Content-Type', 'text/html');
payload = typeof(payload) == 'string' ? payload : '';
}
res.writeHead(statusCode);

//SEND THE RESPOSE FROM THE SERVER
res.end(payload);

//LOG IF YOU NEED TO THE CONSOLE
if(statusCode == 200){
//display in green
console.log('x1b[32m%sx1b[0m',"response on ", method +" " +trimmedPath, " ->", statusCode);
}
else {
//for any non 200 status, display in red
console.log('x1b[31m%sx1b[0m',"response on ", method +" " +trimmedPath, " ->", statusCode);
}
});
});
};

server.router = {
'' : handlers.home,
'account/create': handlers.accountCreate,
'account/edit': handlers.accountEdit,
'account/deleted': handlers.accountDeleted,
'session/create' : handlers.sessionCreate,
'session/deleted' : handlers.sessionDeleted,
'checks/create' : handlers.checksCreate,
'checks/all': handlers.checkList,
'checks/edit': handlers.checksEdit,
'ping': handlers.ping,
'api/users': handlers.users,
'api/tokens': handlers.tokens,
'api/checks': handlers.checks
};

//intitialise the server file
server.init = ()=>{

server.httpServer.listen(config.httpPort, function(){
console.log('x1b[36m%sx1b[0m',"the server is listening on port "+config.httpPort + " ["+config.envName+"] ");
});

server.httpsServer.listen(config.httpsPort, function(){
console.log('x1b[35m%sx1b[0m',"the server is listening on port "+config.httpsPort + " ["+config.envName+"] ");
});
};

module.exports = server;


handlers.js



/*
*This file stores all the handlers
*
*/


//dependencies
let dataLib = require('./data');
let helpers = require('./helpers');
let config = require('../config');

//main code
let handlers = {};

/*
* HTML API HANDLERS BELOW
*
*/

handlers.home = function(data, callback){
console.log("found index ->", data);
callback(200, 'undefined', 'html');
};
module.exports = handlers;


And the error that i am recieving is
enter image description here



Now what i want is to be able to respond if the contentType is html, which is not working right now. If i don't provide the contentType and set the behavior of the api to return json, everything works fine. Any ideas?







javascript node.js rest api






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 17:34

























asked Nov 19 at 17:12









rishabh kalra

83




83








  • 1




    My first thought before looking at your code is to spell handler correctly if your title is anything to go by. Also helpers.convertJSONstr2JSON - there is a native function called JSON.parse for this?
    – Dominic
    Nov 19 at 17:14












  • lol sorry, mistyped it :p
    – rishabh kalra
    Nov 19 at 17:15










  • Are you exporting your handlers in handlers.js like so module.exports = handlers?
    – dotconnor
    Nov 19 at 17:17










  • Please, don't post your code/error messages as images. Firstly we want to copy/paste it and secondly search engines are unable to index that information. So please make sure that any textual information is actually provided in text form.
    – lucascaro
    Nov 19 at 17:18










  • There isn't enough information here to tell what the problem is. You have var selectedHandler = typeof(server.router[trimmedPath]) !== 'undefined' ? handlers[trimmedPath] : handlers.notFound; so start your debugging to figure out which of the ternary options is being picked. Then figure out why it isn't the value you expect.
    – Quentin
    Nov 19 at 17:18














  • 1




    My first thought before looking at your code is to spell handler correctly if your title is anything to go by. Also helpers.convertJSONstr2JSON - there is a native function called JSON.parse for this?
    – Dominic
    Nov 19 at 17:14












  • lol sorry, mistyped it :p
    – rishabh kalra
    Nov 19 at 17:15










  • Are you exporting your handlers in handlers.js like so module.exports = handlers?
    – dotconnor
    Nov 19 at 17:17










  • Please, don't post your code/error messages as images. Firstly we want to copy/paste it and secondly search engines are unable to index that information. So please make sure that any textual information is actually provided in text form.
    – lucascaro
    Nov 19 at 17:18










  • There isn't enough information here to tell what the problem is. You have var selectedHandler = typeof(server.router[trimmedPath]) !== 'undefined' ? handlers[trimmedPath] : handlers.notFound; so start your debugging to figure out which of the ternary options is being picked. Then figure out why it isn't the value you expect.
    – Quentin
    Nov 19 at 17:18








1




1




My first thought before looking at your code is to spell handler correctly if your title is anything to go by. Also helpers.convertJSONstr2JSON - there is a native function called JSON.parse for this?
– Dominic
Nov 19 at 17:14






My first thought before looking at your code is to spell handler correctly if your title is anything to go by. Also helpers.convertJSONstr2JSON - there is a native function called JSON.parse for this?
– Dominic
Nov 19 at 17:14














lol sorry, mistyped it :p
– rishabh kalra
Nov 19 at 17:15




lol sorry, mistyped it :p
– rishabh kalra
Nov 19 at 17:15












Are you exporting your handlers in handlers.js like so module.exports = handlers?
– dotconnor
Nov 19 at 17:17




Are you exporting your handlers in handlers.js like so module.exports = handlers?
– dotconnor
Nov 19 at 17:17












Please, don't post your code/error messages as images. Firstly we want to copy/paste it and secondly search engines are unable to index that information. So please make sure that any textual information is actually provided in text form.
– lucascaro
Nov 19 at 17:18




Please, don't post your code/error messages as images. Firstly we want to copy/paste it and secondly search engines are unable to index that information. So please make sure that any textual information is actually provided in text form.
– lucascaro
Nov 19 at 17:18












There isn't enough information here to tell what the problem is. You have var selectedHandler = typeof(server.router[trimmedPath]) !== 'undefined' ? handlers[trimmedPath] : handlers.notFound; so start your debugging to figure out which of the ternary options is being picked. Then figure out why it isn't the value you expect.
– Quentin
Nov 19 at 17:18




There isn't enough information here to tell what the problem is. You have var selectedHandler = typeof(server.router[trimmedPath]) !== 'undefined' ? handlers[trimmedPath] : handlers.notFound; so start your debugging to figure out which of the ternary options is being picked. Then figure out why it isn't the value you expect.
– Quentin
Nov 19 at 17:18

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379609%2fselectedhandler-is-not-a-function-node-js%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379609%2fselectedhandler-is-not-a-function-node-js%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

To store a contact into the json file from server.js file using a class in NodeJS

Redirect URL with Chrome Remote Debugging Android Devices

Dieringhausen