node.js

Keep MongoDB connection open while running tests using mocha framework

天涯浪子 提交于 2021-02-10 22:52:30
问题 I'm using something akin to How to properly reuse connection to Mongodb across NodeJs application and modules to keep my mongoDB Connection open. This requires all the code to go into a MongoDB.connectDB(async (err) => {...} Block. How would I use this when writing Tests with Mocha. Do I have to use a separate Connection for every test? Like this? const MongoDB = require('../src/mongoUtil') // providing access to the mongo database var events = require('../src/events') // containing all my

Keep MongoDB connection open while running tests using mocha framework

寵の児 提交于 2021-02-10 22:52:22
问题 I'm using something akin to How to properly reuse connection to Mongodb across NodeJs application and modules to keep my mongoDB Connection open. This requires all the code to go into a MongoDB.connectDB(async (err) => {...} Block. How would I use this when writing Tests with Mocha. Do I have to use a separate Connection for every test? Like this? const MongoDB = require('../src/mongoUtil') // providing access to the mongo database var events = require('../src/events') // containing all my

Socket.io: Overwritten generateId() gets executed, but the returned id seems to be ignored

為{幸葍}努か 提交于 2021-02-10 22:50:51
问题 I am trying to overwrite generateId. I used for that the example from the docs. But the behaviour is strange. generateId gets executed, but socket.id is like a regular id, instead of the desired result "custom:id:" + 1 . Code const express = require('express'); const socketIO = require('socket.io'); const http = require('http'); const app = express(); app.set('port', 5000); const server = http.Server(app); const io = socketIO(server); io.engine.generateId = (req) => { console.log('This here

How do I find the duplicate companies and merge them into one and add together their weights [duplicate]

北战南征 提交于 2021-02-10 22:49:50
问题 This question already has answers here : how to group by and sum array of object? [duplicate] (2 answers) Sum javascript object propertyA values with same object propertyB in array of objects (9 answers) Closed 4 months ago . I've tried to use a few different options from filter, reduce and includes but can't wrap my head round how to do this. I have this array below of objects: [ { name: 'GrapeCo', weight: 0.15 }, { name: 'MicroFit', weight: 0.5 }, { name: 'GreenCo', weight: 0.3 }, { name:

How do I find the duplicate companies and merge them into one and add together their weights [duplicate]

早过忘川 提交于 2021-02-10 22:48:07
问题 This question already has answers here : how to group by and sum array of object? [duplicate] (2 answers) Sum javascript object propertyA values with same object propertyB in array of objects (9 answers) Closed 4 months ago . I've tried to use a few different options from filter, reduce and includes but can't wrap my head round how to do this. I have this array below of objects: [ { name: 'GrapeCo', weight: 0.15 }, { name: 'MicroFit', weight: 0.5 }, { name: 'GreenCo', weight: 0.3 }, { name:

How to manipulate DOM using Node js?

孤街浪徒 提交于 2021-02-10 22:22:41
问题 I am new to javascript and Node.js but I am trying to figure out if there is an alternative to document.getElementById() in Node that has the same function. If it cannot be done in Node, is it possible to create a pure js file to manipulate the DOM and a separate Node file. For extra information, what I am trying to do is to convert csv lines into a json object and then update the webpage with new information which is why I want to use document.getElementById(). 回答1: document.getElementById()

How to manipulate DOM using Node js?

给你一囗甜甜゛ 提交于 2021-02-10 22:20:37
问题 I am new to javascript and Node.js but I am trying to figure out if there is an alternative to document.getElementById() in Node that has the same function. If it cannot be done in Node, is it possible to create a pure js file to manipulate the DOM and a separate Node file. For extra information, what I am trying to do is to convert csv lines into a json object and then update the webpage with new information which is why I want to use document.getElementById(). 回答1: document.getElementById()

Node.js - PostgreSQL (pg) : Client has already been connected. You cannot reuse a client

左心房为你撑大大i 提交于 2021-02-10 22:17:38
问题 I am just trying to write simple register/login system. I am trying to find if username exists. Here is the steps : Go localhost:3000/users/register page Fill in all fields and click register button Checking my command line if username exists it should print it with console.log Everything works fine until now. When I go back to the register page, I fill in all fields again and click register button. Then it throws it in command line : Error: Client has already been connected. You cannot reuse

Use Node js to to print data to thermal printer

旧时模样 提交于 2021-02-10 21:55:29
问题 I'm developing an application with Node JS where I need to see all available printers in the user's machine, let the user select one of them and print a receipt. Is there a way to achieve this in macOS and Windows ? Note , I have checked all examples in internet,nothing helped. Kindly provide me an complete example. 回答1: In googling there are few libraries that does this job... Take a look on printer for example, it does all the jobs you require... getPrinters() to enumerate all installed

Node Server Geolocation

六月ゝ 毕业季﹏ 提交于 2021-02-10 21:53:52
问题 Is there a way for a Node server to work out it's accurate (i.e. GPS) location without using the HTML Geolocation API from the browser? It also needs to be disconnected from the internet, i.e not depend on some external lookup. In my case I have a server which is a laptop, not connected to the internet, and physically moving around a location. When the client connects to the server, the server needs to already know where it is, the client may not be in the same location. Imagine the client