Tag: javascript

Why console.log(this) in node return empty object?

When I ran console.log(this) in node it returns empty object console.log(this) // return { } But when I used IIFE in node (function printThisObject(){ console.log(this); // return the global object })(); Can someone explain this to me ?

Insert document only if not already exists

I am creating documents with Subscription.create({ email: req.body.email }, (err, subscription) => { // }); I have made the email field unique in my Mongoose schema, so it’s not possible to create multiple docs with same email. But I don’t care whether a certain email already exists, so I don’t want a duplicate error as […]

Regex to extract login username

Currently, I had one Web chat project, I use socket.io to send and receive messages real time. I need to get the login if user types. I try to use regex but I’m a beginner within and the format can be multiples like: My login is sayuri.mizuguchi My login? So, sayuri.mizuguchi Okay? The format from […]

Cookie is not defined error

I’m getting ‘Cookie is not defined’ error from this code. What went wrong with this code? Please help to fix it. $(‘#save-dashboard’).on(‘click’, function (e) { var filtersNew = $(“#graph-filters”).val(); if (!filtersNew) { alert(‘No Filters!’); } if (cookie.enabled()) { cookie.defaults.path = ‘/’; var cookieFilters = cookie.get(‘cookie-filter-list’); if (cookieFilters) { cookieFilters = cookieFilters + ‘#’ + filtersNew; […]

Deploying Node/Sequelize app to heroku – Issue with PORT

I’m building a Node/Postgres app that I’m deploying to heroku. I’m receiving a timeout error while trying to open the app in production. According to Heroku, the error I’m receiving comes from database or port connection issues. I believe my database connection is fine, I’m getting a log that the connection was successful. Unsure if […]

Viewing objects in javascript ( under the hood )

Im very curious as to how objects are displayed in nodejs and in this case promises. When using console.log(promiseObject) the output is of type {state:pending} This seems very weird to me since a function .then() is invoked on that object so i would expect to see that there. Try for yourself with this code function […]

return resolve error in node function

Why wont usernametoid function return the acual id? cause im trying to send the result of the userdata as the return. In this case, i want to only send the userdata`s _id attribute. but it seems like it wont work. console.log(userdata._id); // works return resolve(userdata._id); // wont work. output of variable userdata: { cash: 7300002, […]

Delete item from nested array in Schema using moongoose

I need help with removing this item from nested array. I tried used $http.delete but this method deleted whole ObjectID from database, and second problem is that I can’t connect the click on the “removing” button with backend code. My code: var product = new Schema({ title: String, price: String, description: [ObjectID] }); Index.html <form […]

How to connect to tcp server via node.js/socket.io from client?

I’ve set up a tcp server using node.js/socket.io, but I can’t figure out how to connect to it via the client side. I’ve tried the client code from http://socket.io/#how-to-use but it sends a http request to a tcp server and after the connection is made, the webpage does not finish loading the the loading circle […]

Failed to list gulp tasks in WebStorm 2016.1

I am using Gulp 3.9.1, node 5.7.1, npm 3.10.3, and WebStorm 2016.1. When I try to setup gulp for my project, I get the following error: /usr/local/bin/node /Users/msbauer/Developer/workspaces/provider-data-management/node_modules/gulp/bin/gulp.js –color –gulpfile /Users/msbauer/Developer/workspaces/provider-data-management/gulpfile.js error: unknown option `–color’ Process finished with exit code 1 And when I force to rescan tasks: Failed to list gulp tasks in provider-data-management/gulpfile.js: […]

Node.js is the Best Javascript runtime in the world.