I would like to create a sort of a ‘dashboard’ on a capped collection (which is used as a log table) on my Mongo database. This is how I create the collection: I do a collection.find(), with options tailable:true, awaitdata:true, and numberOfRetries:-1 (infinite retries). What puzzles me is that I’d expect the find().each() loop to wait for new data (messages)…
Tag: node.js
Node.js – “TypeError – res.setHeader is not a function”
I’m trying to load JSON from a URL to a variable and send it back to the client’s javascript Every time I run the code the server says that res.setHeader isn’t a function and the rest breaks. Answer Both post and getJSON callbacks have same res variable name. Try this:
What is “entry point” in npm init
I have an empty new project, when i run npm init i got a list of questions to answer, for example: I am really confused about the one that says “entry point”, Should this be my index.html file or my app.js or is it something else? Answer Quoting from this blog post: Entry point is the javascript file that will
Is there a way to create interfaces in ES6 / Node 4?
ES6 is fully available in Node 4. I was wondering whether it includes a concept of interface to define method contracts as in MyClass implements MyInterface. I can’t find much with my Googling, but maybe there is a nice trick or workaround available. Answer Interfaces are not part of the ES6 but classes are. If you really need them, you
Open a folder window using explorer.exe or finder using node js
I was wondering if there was a way to open a folder location via node js. I found this library but it only opens files and URLs. Edit: Fuser’s answer put me on the right track and I found this: http://documentup.com/arturadib/shelljs Either his method or this will both work. Answer Just shell out to explorer with the desired folder.
require is not defined? Node.js [duplicate]
This question already has answers here: Client on Node.js: Uncaught ReferenceError: require is not defined (11 answers) Closed 5 months ago. Just started working with Node.js. In my app/js file, I am doing something like this: app.js When I’m in my terminal and run node app.js, the console spits out ‘running server!’, but in my browser I get, Uncaught ReferenceError:
ForbiddenError: invalid csrf token, express js
I’ve tried to get csurf to work but seem to have stumbled upon something. The code so far looks like this: index.ejs Where you insert password and username in the form. app.js Where I’ve put csrf after session and cookie parser. index.js What I get after submiting the form, no matter if I insert the correct username and password or
Run JavaScript in Visual Studio Code
Is there a way to execute JavaScript and display the results using Visual Studio Code? For example, a script file containing: I assume that Node.js would be needed but can’t work out how to do it? By Visual Studio Code I mean the new Code Editor from Microsoft – Not code written using Visual Studio. Answer This solution intends to
node.js mongodb .. the (immutable) field ‘_id’ was found to have been altered
I have some problem when I try to upsert my object with new ones(parsed from xml file),but I got the following error: Here is my code: I tried to use hints like: but they didn’t help. So I don’t want to update my product._id , I just want to update the other fields. Answer When you do new Product(), a
Defining an array as an environment variable in node.js
I have an array that I pull data from. Since I’m using heroku, it may be better to replace it with an environment variable, but I’m not sure how to do that. Is using a JSON string as an environment variable the way to go? Answer In this scenario, it doesn’t sound like an env var is the way to