Node.js 500 Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about node js express error handling Stack Overflow the company Business Learn more about hiring developers or posting ads with
Express Throw Error
us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is express router error handling a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Node JS: 500 Server Error up vote 1 down vote favorite I am kinda node js error handling new to this node js thing. So, please bear with me. I have got a json string array in dotNetFin.js. I am not sure as to why error comes up(when i switch over to About page), and, in the command prompt window, it shows up "Undefined is not a function" Also, everything works fine if I include that json array in app.js. Well here is my code: app.js var express =
Node Js Error Object
require('express'); var app = express(); app.set('port', process.env.PORT || 3000); app.get('/', function (req, res) { res.render('home'); }); var teamData = require('./dotnetFin.js'); app.get('/about', function (req, res) { res.render('about', { dotnet: teamData.getTeamData() }); }); //custom 404 page app.use(function (req, res) { res.type('text/plain'); res.status(404); res.send('404 Not Found'); }); app.use(function (err, req, res, next) { console.log(err.stack); res.type('text/plain'); res.status(500); res.send('500 Server Error'); }); app.listen(app.get('port'), function () { console.log('Express started on server' + app.get('port')); }); var handleBars = require('express3-handlebars').create({ defaultLayout: 'main' }); app.engine('handlebars', handleBars.engine); app.set('view engine', 'handlebars'); dotnetFin.js var dotnetTeam = ["V", "M", "A", "H", "A", "G", "K"]; var getTeamData = function () { return dotnetTeam; }; main.handlebars
Fin
{{{body}}} about.handlebarsAbout Fin
Dotnet Team
{{dotnet}}
Error Snapshot: node.js share|improve this question asked Oct 20 '15 at 10:49 Ajay 3031417 2 In dotnetFin.js, do you export the function via module.exports.getTeamData = getTeamData ? –Himmet Avsar Oct 20 '15 at 11:00 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote accepted You need to export your getTeamData function from dotnetFin.js file. So just change, var getTeamData = function () { return dotnetTeam; }; with exports.getTeamData = function () { return dotnetTeam; }; and your API should work. You always need to export vahere for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies node js error handling best practices of this site About Us Learn more about Stack Overflow the company express error handling best practices Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users
Express Error Handler Not Called
Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a http://stackoverflow.com/questions/33234641/node-js-500-server-error minute: Sign up Node js express 500 server error up vote 0 down vote favorite When i try to make a call to a method exposed through nodejs server i got 500 error it says protocol version not supported The call to the method was working perfect if i remove the socket.io configration... var express = require('express'); var app = express(); var http://stackoverflow.com/questions/21280901/node-js-express-500-server-error http = require('http'); var server = http.createServer(app); app.use(express.bodyParser()); app.use(express.static(__dirname + '/pollapp')); app.get('/pollapp/PollServer.js', function (req, res) { res.sendfile(__dirname + '/index.htm'); }); app.get('/pollapp/PollServer.js/api/listPoll', function (req, res) { //....code }); var io = require('./hostedSocket').listen(server); io.configure(function () { io.set('resource', '/pollapp/PollServer.js'); //Where we'll listen for connections. }); server.listen(process.env.PORT); Here call to /pollapp/PollServer.js/api/listPoll gives me 500 server error (Protocol version not supported) but if i remove io.configure(function () { io.set('resource', '/pollapp/PollServer.js'); }); then things are working well and good. But if i remove the io.configure then socket is not working. javascript node.js express socket.io share|improve this question asked Jan 22 '14 at 10:54 maddygoround 1,087823 add a comment| 1 Answer 1 active oldest votes up vote 0 down vote accepted You're trying to mix the socket.io resource location with Express routes, which – judging by the socket.io code and the errors you're getting – isn't going to work. What happens is that any request starting with /pollapp/PollServer.js will be handled by socket.io, and not get passed to Express. So you need to keep those two paths separated. Perhaps this works better (untested): io.set('resource', '/pollapp/PollServer.js/socket.io'); And in your client:
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of http://stackoverflow.com/questions/17955973/internal-server-error-for-node-js this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up error handling Internal server error for node.js up vote 1 down vote favorite I have the following code to using node.js to serve a webpage in static/college.html But it hit the error and shows in browser "Internal server error: could not read file"which is the line printed in code for testing. Any suggestions and how to fix this? Thanks // Require the functionality we need node js error to use: var http = require('http'), url = require('url'), path = require('path'), mime = require('mime'), path = require('path'), fs = require('fs'); // Make a simple fileserver for all of our static content. // Everything underneath