node.js

Mongodb findOne () not return value nodejs

柔情痞子 提交于 2021-02-17 02:07:15
问题 Hi Guys i try to do some email verification after a user suscrib to my api but when i do user.FindOne(token), the user is find but i not able to get the value of the user in the database the return me a big ass array and i don't see wich value to choose. my code: ValidationFunction: const User = require('../models/User'); const Token = require('../models/Token'); module.exports = function (req, res, next) { const headToken = req.header('token'); const token = Token.findOne({ token: headToken

Mongodb findOne () not return value nodejs

拜拜、爱过 提交于 2021-02-17 02:06:17
问题 Hi Guys i try to do some email verification after a user suscrib to my api but when i do user.FindOne(token), the user is find but i not able to get the value of the user in the database the return me a big ass array and i don't see wich value to choose. my code: ValidationFunction: const User = require('../models/User'); const Token = require('../models/Token'); module.exports = function (req, res, next) { const headToken = req.header('token'); const token = Token.findOne({ token: headToken

Receiving Promise <Pending> instead of value

邮差的信 提交于 2021-02-17 02:02:13
问题 I have a a object that when I'm printing that it's returning Promise <Pending> (I've checked the type of getRateable and it is object) getRateable = getRateableEntitiesTx(tx, hashtagList); I can't have access to the value by this : getRateableEntitiesTx(tx, hashtagList).then((res) => {return res}) If it's a Promise why it's not returning the res properly? Thanks in advance for help 回答1: You can't return the value from an async function because the function returns before the value has been

NestJS Jest cannot find module with absolute path

余生长醉 提交于 2021-02-17 01:56:28
问题 I have a quite new NestJS application. I'm trying to run unit tests, but they keep failing due to 'cannot find module..' when using absolute paths ("src/users/..."), but works when using relative paths ("./users/.."). Is there anything wrong with my configuration here? Jest setup in package.json: "jest": { "moduleFileExtensions": [ "js", "json", "ts" ], "rootDir": "src", "testRegex": ".spec.ts$", "transform": { "^.+\\.(t|j)s$": "ts-jest" }, "coverageDirectory": "../coverage", "testEnvironment

What is the purpose of node_modules folder?

孤人 提交于 2021-02-16 20:53:27
问题 I would like to know what is exactly node_modules folder and what is for. I know when we download any library with npm, the library goes to node_modules, but I know when we are going to upload it to github we have to ignore the node_modules folder because it takes a lot of space. Through package.json we can download all dependencies using npm i, my question is... Let's say I wanna deploy my app/website to some server/host, Do I have to upload the node_modules folder to server as well? And

What is the purpose of node_modules folder?

情到浓时终转凉″ 提交于 2021-02-16 20:53:08
问题 I would like to know what is exactly node_modules folder and what is for. I know when we download any library with npm, the library goes to node_modules, but I know when we are going to upload it to github we have to ignore the node_modules folder because it takes a lot of space. Through package.json we can download all dependencies using npm i, my question is... Let's say I wanna deploy my app/website to some server/host, Do I have to upload the node_modules folder to server as well? And

Joi Validation Regex or pattern

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-16 20:23:49
问题 I want to joi use regex pattern which define in variable I have a variable pattern which contains regex i.e pattern = "/^[0-9+]{7}-[0-9+]{1}$/" and this pattern send to Joi module and want to confirm module.exports = { save: { body: { match: Joi.string().regex(pattern).required } } } I know validation work if I use this module.exports = { save: { body: { match: Joi.string().regex(/^[0-9+]{7}-[0-9+]{1}$/).required } } } But in my case every time regex will different. So I can not use above

Request-Promise: do promise cache the result

谁都会走 提交于 2021-02-16 20:05:30
问题 I'm using Request-Promise ( See code below ). Question: If I cache a promise, do it cache the result or each time ask a new one? Example: var cachedPromise = getTokenPromise(); cachedPromise.then(function(authorizationToken1) { //... }); cachedPromise.then(function(authorizationToken2) { //... }); //QUESTION: Is right that authorizationToken1 equals authorizationToken2 getTokenPromise() function: var querystring = require('querystring'); var rp = require('request-promise'); /** * Returns an

Request-Promise: do promise cache the result

五迷三道 提交于 2021-02-16 20:04:30
问题 I'm using Request-Promise ( See code below ). Question: If I cache a promise, do it cache the result or each time ask a new one? Example: var cachedPromise = getTokenPromise(); cachedPromise.then(function(authorizationToken1) { //... }); cachedPromise.then(function(authorizationToken2) { //... }); //QUESTION: Is right that authorizationToken1 equals authorizationToken2 getTokenPromise() function: var querystring = require('querystring'); var rp = require('request-promise'); /** * Returns an

using .save() vs findByIdAndUpdate() for removing item from array

你离开我真会死。 提交于 2021-02-16 19:59:41
问题 I am using .pull to remove a record from an array in mongo db and it works fine, but a comment I read somewhere on stack overflow (can't find it again to post the link) is bothering me in that it commented that it was bad to use .save instead of using .findByIdAndUpdate or .updateOne I just wanted to find out if this is accurate or subjective. This is how I am doing it currently. I check if the product with that id actually exists, and if so I pull that record from the array. exports