I am currently building a Nodejs, Express, Sequelize (w. PostgreSQL) app, and have run into a few problems with using promises together with transactions and loops. I am trying to figure out how to use a for loops in a transaction. I am trying to loop through a list of members and create a new user in the database for
Tag: node.js
How to pass parameter to a promise function
this might seem a silly question but I am a newbie in this topic. I am working on promises on node js. And I want to pass parameter to a promise function. However I could not figure it out. and the function is something like Answer Wrap your Promise inside a function or it will start to do its job
Node + Passport, Error: Authentication strategies must have a name
I’m trying to initialize a SAML strategy during the require line. Something like this: but am getting the error: or TypeError: Cannot read property ‘name’ of undefined at Authenticator.use if a custom strategy name is not defined: passport.use(myStrat); . I’ve had it like this (which works): but I wish to change it because I need to call passport-saml’s Stragety.generateServiceProviderMetadata() function
How do I properly insert multiple rows into PG with node-postgres?
A single row can be inserted like this: This approach automatically comments out any special characters. How do i insert multiple rows at once? I need to implement this: I can just use js string operators to compile such rows manually, but then i need to add special characters escape somehow. Answer Following this article: Performance Boost from pg-promise library,
chain promises in javascript
I’ve created many promises like that, in order to create object in my database. At the end, I want call all my promises in the order I want. (because somes object depend of other, so I need to keep that order) So I expect to see : Unfortunately, this messages are shuffled and I don’t understand what. Thanks Answer Looks
Express.Static not working for subdirectory
Express.static is working great for any view in root directory, but it breaks when I add a subdirectory. Works: Doesn’t Work: I’m guessing __dirname is changed to whatever directory the get request is made from, but I just want to use the root (/public) directory for all static requests. Answer Use it this way:
How to use XHR API in Node.js?
This is a follow-up to my previous question Suppose I’ve some javascript code, which runs fine on client (in a browser). This code makes a lot of XHR calls using the browser API. Now I would like to run this code in node.js. Does node.js provide the XHR API as in browser ? Answer Natively Node.js does not provide the
Running npm globally installed packages
Can someone please explain how do node’s globally installed behave. It is really confusing me. If I install a package (with executables) such as http-serverglobally I can run it with: But if I do I get I suspect my ternpackage in emacs is trying to run it with node hence breaking. Why is this happening? Why can’t node find the
Sequelize: Cannot set a new unique constraint message
I am trying to setup a validation message for unique constraint violation for the fields username and email. However, whenever an already taken username is entered, it shows the message defined for the email property, but shows the input for the username property and also says that this input is for the username property. How would I fix this? Here
In Express.js, should I return response or not?
For Express.js 4.x I can’t find wether I should return the response (or next function) or not, so: This: Or this: And what is the difference? Answer You don’t. The (req, res) signature tells express this is the last function in the chain, and it does not expect a return value from this function. You can add a return statement,