NodeJs callback and parameters

Issue I came across this piece of code which needs some clarification. http://expressjs.com/en/guide/writing-middleware.html#:~:text=The%20next%20%28%29%20function%20is%20not%20a%20part,%E2%80%9Cnext%E2%80%9D.%20To%20avoid%20confusion%2C%20always%20use%20this%20convention. Refer section : "Configurable middleware" How is it possible that "req", "res" and "next" can be referred inside the exported function directly ? I mean neither the

Continue reading

Nodejs Question about circular dependency

Issue I was testing circular dependency with commonjs. //index.js console.log(‘main starting’); const a = require(‘./a.js’); const b = require(‘./b.js’); console.log(‘in main, a.done = %j, b.done = %j’, a.done, b.done); //a.js console.log(‘a starting’); exports.done = false; const b = require(‘./b.js’); console.log(‘in

Continue reading

Node.js: install only required modules of googleapis

Issue I am using NodeJs to send FCM notifications. Below is my code const errorCodes = require(‘source/error-codes’); const PropertiesReader = require(‘properties-reader’); const serviceAccount = require("service-account.json"); const fetch = require(‘node-fetch’); var { google } = require(‘googleapis’); var MESSAGING_SCOPE = ‘https://www.googleapis.com/auth/firebase.messaging’; var

Continue reading

How to check UUID using regular expressions?

Issue In order to make validation over a api, i’m send companyId as UUID like: 71158c1a-56fd-4dd4-8e7f-fb95711a41de To have this validation I used jsonschema with the following patterns (test all 3 of them): /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$ /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gi [\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12} jsonschema: companyId: { type: "string",

Continue reading

how to output console.log in url

Issue this fs = require(‘fs’); var data = fs.readFileSync(‘./number/data’, ‘utf8’); console.log(data) i can change to this await page.goto(‘https://web.whatsapp.com/send?phone=console.log(data);text=kaka’); Solution Do you want to output the contents of data into the URL? If yes then use string interpolation. await page.goto(`https://web.whatsapp.com/send?phone=${data};text=kaka`); Answered

Continue reading

How to get node-sqlite3 working on Mac M1?

Issue I’m using Rosetta 2 with Homebrew and have sqlite3 installed. I added these to my ~/.zshrc so that the node compiler can find the brew installs: export PATH="/usr/local/opt/sqlite/bin:$PATH" export LDFLAGS="-L/usr/local/opt/sqlite/lib" export CPPFLAGS="-I/usr/local/opt/sqlite/include" I’m using installing using npm install sqlite3,

Continue reading

Suggest how to write this more compact

Issue Many equal properties names in this code. Is it possible to make it a lot compact ? constructor(product) { this.session = SessionBuilder.create(); this.id = product.id; this.name = product.name; this.root = product.root; this.pics = product.pics; this.sizes = product.sizes; this.colors =

Continue reading

Unable to fill mongodb document with external api data

Issue I am trying to fill my mongodb document with data from unsplash and randomuser api. const userdata = await axios.get("https://randomuser.me/api/?results=51"); const imagedat = await axios.get( "https://api.unsplash.com/photos/random/?count=51&client_id=GWDzPpjHk743C2QnVBRxu8PtmOI3npF5sePZZ7o0pg4" ); I call both apis for 51 results but after 22 results the

Continue reading

MSBUILD : Configuration error MSB4148 "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0" has zero length

Issue I’m trying yo install electron-chromedrive by using yarn, so by doing this command: yarn add –dev electron-chromedriver –network-timeout 100000 But it gives the following error: MSBUILD : Configuration error MSB4148 "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0" has zero length Precisely: gyp ERR! build error

Continue reading

to be under different domain, why axios.post dont work

Issue https://github.com/skyturkish/e_commerce_advance this is the repo index.js const express = require(‘express’) const bodyParser = require(‘body-parser’) const UserService = require(‘./services/user-service’) const app = express() app.set(‘view engine’, ‘pug’) app.use(bodyParser.json()) app.get(‘/’, (req, res) => { res.render(‘index’) }) app.get(‘/users/all’, async (req, res) => {

Continue reading