I am currently struggling to run my Node.js server. What I want to do: Upload a CSV-File from mobile device to my local server and save it on the file system Read each line of the .csv-File and save each row to my MongoDB database Uploading and saving the file works flawlessly. Reading the .csv-File and savin…
Tag: node.js
How to generate unique ID with node.js
How to set a variable value with database query callback? How I can do it? Answer It’s been some time since I used node.js, but I think I might be able to help. Firstly, in node, you only have a single thread and are supposed to use callbacks. What will happen with your code, is that base.getID query wi…
NodeJS: Would App Run Faster if Freeze Objects?
Most of my objects/functions do not change. Would the application run faster if I freeze most of the objects via Object.freeze(object)? Or will it make no difference at all? Answer Freezing (and sealing) causes a signficant performance hit instead of a gain across various browsers. Just take a look at some of…
Unable to run node app.js file
I am learning node.js and I am trying to run the app.js file using the command node app.js but the bash returns nothing (no errors either). Here are the steps I followed: $ brew install node $ sudo npm install -g express $ sudo npm install -g express-generator after i get into a new folder I created I run $
What does it mean by “message queue” in this link?
I was trying to understand what’s an event loop in JavaScript. Came across Mozilla Developer Network’s link about event loop. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/EventLoop It mentions Queue A JavaScript runtime contains a message queue, which is a list of messages to be p…
Create an array with all numbers from min to max without a loop
I have two numbers, min and max, and I want to create an array that contains all number between them (including min and max). The most obvious approach is to use a for loop for this, and push the single values onto an array. Nevertheless, this seems to be a quite naive approach, i.e. it’s imperative pro…
Is it necessary to set a Content-Type in Node.js?
Just started playing with Node.js and after seeing a few examples I see that usually the Content-Type is set before returning some content. Usually something like this for HTML: For image: I read the docs for .write() and it says if no header is specified “it will switch to implicit header mode and flus…
How to add rooms in Node.js with Socket.io?
I have been following up many articles to learn making chat application with Node.js and Socket.io. Everything is clear and I can make an application moving messages from client to server and emitting to all etc but only one thing is not clearing and cannot figure this out. How can I add rooms to io.sockets.m…
How to create a simple http proxy in node.js?
I’m trying to create a proxy server to pass HTTP GET requests from a client to a third party website (say google). My proxy just needs to mirror incoming requests to their corresponding path on the target site, so if my client’s requested url is: The following resource should be served: Here is wh…
On an EventEmitter, how can I know all the events I can listen to?
Supposing I have an object that inherited from EventEmitter, like a stream or any other, is there a good way to know all the events I can listen to, and all the attached event listeners ? I think the second part of the question is easy, emitter.listeners(event) will tell me all the listeners to an event. But …