How to handle the error: Error: getaddrinfo ENOTFOUND unexistantwebsite.com with the node package Websocket(Ws) without making the app crashing ?
I just tryed to create a websocket connect on an non-existant website and that make all the app crashing :
var ws = new WebSocket('wss://unexistantwebsite.com/', {
binaryType: "arraybuffer"
});
I tried many way to handle the error but nothing works.
Surround with try catch: KO
Add .catch on the constructor end: KO (even invalid that's normal I suppose)
I just want to handle the error avoiding the app to crash.
Related
I have been trying to connect database locally to mongodb using nodejs but there are some errors i'm facing some errors while doing that.
In my main folder there is only one connection file named as db.js and other files are package.json and node_modules. This is error I got after running the node db.js at particular location I have installed mongoose also using npm command.
and after using the command node --trace-deprecation I got the following error log.
Here's the code of db.js:-
const mongoose=require('mongoose');
mongoose.connect('mongodb://localhost:27017').then(()=>{
console.log(`conncn established!!\n`);
}).catch((err)=>{
console.log('no connection',err);
})
// module.exports=mongoose;
// "mongodb://localhost:27017/Blogs_db -->it is the connection string for Blogs_db tried to but this //string also but it is not working
I have checked whether my server is running or not and tried to make the new folder and to follow the process again but it still shows the connection error
Go the answer and it is simple just to replace the local host in the connection string with 0.0.0.0 and it worked[Heres the output after replacing the localhost in above code with 0.0.0.0]
I'm working on an app using React Native and Expo. I'm not new to react native, but this is the first job that required the use of expo. My problem is I'm sending error messages from the server that would be usefull for front end logic, but expo constantly overrides the error with an error that Expo generates, and I can't figure out how to retreive the message from the server.
Server code:
...Random server logic
return res.status(400).json({ msg: "invalid user credentials" });
What I receive in the expo app.
message(pin):"Request failed with status code 402"
name(pin):"Error"
stack(pin):"Error: Request failed with status code 402 at createError (http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:176428:17) at settle (http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:176418:14) at EventTarget.handleLoad (http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:176316:9) at EventTarget.dispatchEvent (http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:32785:27) at EventTarget.setReadyState (http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:31854:14) at EventTarget.__didCompleteResponse (http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:31696:16) at http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:31806:47 at RCTDeviceEventEmitter.emit (http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:7450:37) at MessageQueue.__callFunction (http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:3225:44) at http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:2938:17"
I've followed this tutorial http://kroltech.com/2013/12/boilerplate-web-app-using-backbone-js-expressjs-node-js-mongodb/ to set up my backend node.js server, but instead of using backbone-marionette for the frontend I want to try ember. Therefore, having successfully set up the server, I am now going through this tutorial for ember http://emberjs.com/guides/getting-started/.
The problem I'm running into is including external templates into my ember routes. With this code and the todos template written in the browser the app works fine.
var Ember = require('ember');
window.Todos = Ember.Application.create();
Todos.Router.map(function() {
this.resource('todos', { path: '/' });
});
However, with a template written in ./templates/application.hbs and using browserify to try this,
Todos.Router.map(function() {
this.resource(require('./templates/application.hbs'), { path: '/' });
});
I get the errors shown below.
Uncaught TypeError: undefined is not a function myapp.js:46841
Error: Assertion Failed: The URL '/' did not match any routes in your application
at new Error (native)
at Error.Ember.Error (http://localhost:3300/js/myapp.js:12978:19)
at Object.Ember.assert (http://localhost:3300/js/myapp.js:12141:11)
at http://localhost:3300/js/myapp.js:47347:15
at invokeCallback (http://localhost:3300/js/myapp.js:22081:19)
at publish (http://localhost:3300/js/myapp.js:21751:9)
at publishRejection (http://localhost:3300/js/myapp.js:22179:7)
at http://localhost:3300/js/myapp.js:30448:7
at Object.DeferredActionQueues.flush (http://localhost:3300/js/myapp.js:18195:24)
at Object.Backburner.end (http://localhost:3300/js/myapp.js:18283:27) myapp.js:15589
Uncaught Error: Assertion Failed: Error: Assertion Failed: The URL '/' did not match any routes in your application
I was hoping someone could shed some light on how to include external templates in an ember router. Thanks!
Thanks for looking into it! I think I did a poor job explaining my question - I understood that it was the template name but I didn't understand how to include that in my application. I searched around a bit more and found grunt-ember-templates.
For future reference, they have really good docs to get you set up, this is what my emberTemplates code looked like.
emberTemplates: {
compile: {
options: {
templateBasePath: 'client/src/templates'
},
files: {
'build/templates.js': ['client/src/templates/*.hbs']
}
}
},
And then I just added 'application' as my route template name.
Don't forget to compile all of build/ in your app build.
I'm new into node.js and i chose geddy to start one sample app.
I tried to execute this command:
geddy scaffold news title:string
but when I run the application, i received an error
Error: 500 Internal Server Error
TypeError: ejs:11
<%- linkTo(news[i].title, newsPath(news[i].id)); %>
string is not a function
at handleErr (C:\Users\tschl_000\AppData\Roaming\npm\node_modules\geddy\lib\template\engines\ejs.js:58:15)
at Object.rethrow (C:\Users\tschl_000\AppData\Roaming\npm\node_modules\geddy\lib\template\engines\ejs.js:90:41)
at eval (eval at (C:\Users\tschl_000\AppData\Roaming\npm\node_modules\geddy\lib\template\engines\ejs.js:88:10), :2:925)
at C:\Users\tschl_000\AppData\Roaming\npm\node_modules\geddy\lib\template\engines\ejs.js:101:17
at ejs.render (C:\Users\tschl_000\AppData\Roaming\npm\node_modules\geddy\lib\template\adapters\ejs.js:28:10)
at Adapter.render (C:\Users\tschl_000\AppData\Roaming\npm\node_modules\geddy\lib\template\adapters\index.js:122:22)
at Partial.renderSelf (C:\Users\tschl_000\AppData\Roaming\npm\node_modules\geddy\lib\template\partial.js:128:28)
at handleData (C:\Users\tschl_000\AppData\Roaming\npm\node_modules\geddy\lib\template\partial.js:101:16)
at C:\Users\tschl_000\AppData\Roaming\npm\node_modules\geddy\lib\template\partial.js:119:9
at fs.js:266:14
i think that this error is happening by the singular/plural problem,
because when i removed the call to "newsPath", this worked.
Anyone know how to make it work?
I am very new to node.js, I just followed the steps to create a simple node.js application. Here it is on github
I ran the command jitsu deploy from the terminal to deploy it on nodejitsu, however I got this error right here, please any help on what could be wrong with code files?
Here is the code on git hub
Here is the error that is appearing:
prompt: Is this ok?: (yes) yes
info: Creating snapshot 0.0.0-5
info Uploading: [=============================] 100%
info: Updating app test
info: Activating snapshot 0.0.0-5 for test
info: Starting app test
error: Error running command deploy
error: Nodejitsu Error (500): Internal Server Error
error: There was an error while attempting to deploy the app
error:
error: Error spawning drone
error: Script took too long to listen on a socket
error:
error: This type of error is usually a user error.
error: Error output from Haibu:
error:
error: Error: Error spawning drone
error: at Object.onTimeout [as _onTimeout] (/root/haibu-orchestra/node_mod
ules/haibu/lib/haibu/core/spawner.js:396:15)
error: at Timer.list.ontimeout (timers.js:101:19)
help: For help with this error contact Nodejitsu Support:
help: webchat: <http://webchat.nodejitsu.com/>
help: irc: <irc://chat.freenode.net/#nodejitsu>
help: email: <support#nodejitsu.com>
You're server.js is exporting a function, but that doesn't get run. Just the body of your start function as top-level code directly inside the server.js module so that it executes when nodejitsu starts your application.
Nodejitsu is very picky about how quick your deployments listen on the system. There is a certain time frame between the start of deployment and end of deployment before your deployment is considered a failure. When it doesn't listen on a port for so long, it ends up giving you this error.
Rather than using your current start function, why don't you try creating your HTTP socket in index.js and then passing it into your start function as well, since you're already passing routes and handle to it?
For example, in index.js:
var http = require('http'),
server = http.createServer().listen(8080);
start(server, router.route, handle);
Then, rather than using http.createServer(onRequest).listen(8080) in your server.js file, you can use something like:
var start = function (server, route, handle) {
function onRequest(request, response) {
/* Your request stuff here */
}
server.on('request', onRequest);
};
This would most likely solve the whole problem.