Suppose I want to have REST endpoints which look roughly like this: CRUD on each if makes sense. For example, /user POST creates a new user, GET fetches all users. /user/user_id GET fetches just that one user. Items are user specific so I put them under user_id, which is a particular user. Now to make Express…
Tag: node.js
How to read and save attachments using node-imap
I’m using node-imap and I can’t find a straightforward code example of how to save attachments from emails fetched using node-imap to disk using fs. I’ve read the documentation a couple of times. It appears to me I should do another fetch with a reference to the specific part of a message be…
Socket.io error hooking into express.js
I’m trying to hook socket.io and express.js together: At the line: var io = require(‘socket.io’).listen(app); I’m getting an error: There doesn’t seem to be anything on SO/google about this error… Answer You can do it without using http module app.listen return a server ins…
Reload Express.js routes changes without manually restarting server
I tried express-livereload, but it just reloaded view files. Should I use another tool, or this one can be configured to watch for my index.js file which runs the server? I read that options are the same as node-livereload, and default for watched files include .js files. Any URL you know with a simple config…
How to set cell width when export .xlsx files with js-xlsx
I am trying to set a fixed column/cell width to my exported excel files with js-xlsx. EDIT: Here is the source of js-xlsx: https://github.com/SheetJS/js-xlsx Answer I found a snippet the the write test here https://github.com/SheetJS/js-xlsx/blob/master/tests/write.js#L14-L19 For quick reference, where ws is …
What’s the proper way to document callbacks with jsdoc?
I’ve spent quite a while scouring the internet looking for the best way to properly document callbacks with jsdoc, but unfortunately, I haven’t found a great one yet. Here’s my question: I’m writing a Node.js library for developers. This library provides multiple classes, functions, an…
Socket.io not sending cookies in the handshake causing the request to stall
Let me explain my setup. I have multiple domain names that are all CNAME records for a main domain name, such as example.com. example.com -> serverIP company1.example.com -> example.com company2.example.com -> example.com I’m basically developing white labeled versions of our software, where th…
Node.js synchronously loop or iterate over asynchronous statements
I want to do a for each loop but have it run synchronously. Each iteration of the loop will do an http.get call and that will return json for it to insert the values into a database. The problem is that the for loop runs asynchronously and that causes all of the http.gets to all run at once and my
Socket.io – listen events in separate files in node.js
For example my idea is: File1.js File2.js This code is for a node server, will I have problems with this code? Answer Nope, just use the same “io” object. File1.js File2.js app.js index.html
Express Node.js doesn’t work
I installed express 4 along with node.js,npm and express-generator on my ubuntu 12.04 and created an app using the following commands: Now what I should get is “Express server running on port 3000” but instead the command simply executes and doesn’t leave any message or error. So I have no i…