express

jest test emitting events for eventemitter objects (express)

家住魔仙堡 提交于 2020-04-17 20:38:49
问题 trying to get an inspiration from jest test emitting events for eventemitter objects (http) didn't solve my pain with express. assume the following nodejs code // server.js const express = require("express"); const app = express(); const server = app.listen(8080,'127.0.0.1') .on("error", err => { // ... }); module.exports = server; how to write a test using jest to emit the http "error" event (to cover the error event handler)? i tried: // server.test.js it("should handle error", () => { jest

jest test emitting events for eventemitter objects (express)

半城伤御伤魂 提交于 2020-04-17 20:38:07
问题 trying to get an inspiration from jest test emitting events for eventemitter objects (http) didn't solve my pain with express. assume the following nodejs code // server.js const express = require("express"); const app = express(); const server = app.listen(8080,'127.0.0.1') .on("error", err => { // ... }); module.exports = server; how to write a test using jest to emit the http "error" event (to cover the error event handler)? i tried: // server.test.js it("should handle error", () => { jest

Node.js How to get previous url

戏子无情 提交于 2020-04-16 05:47:33
问题 I want to get previous url, for example in all my /admin routes I open a form where the admin needs to re-enter his password to get redirected to the route he requested, but the problem is after I validate his password and I try to redirect him to the route he initially requested, I don't have this route anymore, it's lost. For example, admin requests /admin/register, a form appears that posts to validate-password , and then if it finds that the password matches (correct password entered), it

mongoose save multi level nested objects

﹥>﹥吖頭↗ 提交于 2020-04-16 05:03:11
问题 I try to implement my first mongoose based REST API. I tried now for days but cannot get this up and running. I would like to save the survey with an array of controls and for each control an array of controlProperties. In different scenarios I got it to save survey with controls array but without controlProperties and sometime with not even controls array. Can someone please help me understand my error? Thanks a lot. The structure is as follows: Survey -- Array of control -- Array of

Can't install express because npm install express error

最后都变了- 提交于 2020-04-16 03:17:12
问题 I'm receiving the following errors when trying to install express : npm ERR! code ERR_OSSL_PEM_NO_START_LINE npm ERR! errno ERR_OSSL_PEM_NO_START_LINE npm ERR! request to https://registry.npmjs.org/express failed, reason: error:0909006C:PEM routines:get_name:no start line 回答1: Type this command npm set registry http://registry.npmjs.org/ and after that try again npm install express as per this issue it is a certificate related problem 回答2: I also had a problem like that... and looking around

NestJS Interceptors: Unable to set HTTP Headers on outgoing requests

会有一股神秘感。 提交于 2020-04-16 03:05:33
问题 I am writing APIs in NestJS which have a set of common headers. I decided to use interceptors in order to append headers to outgoing requests. The headers do not get appended to the request and hence the request keep on failing. Interceptor import * as utils from '../utils/utils'; import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common'; import { HEADERS } from '../middlewares/headers.constant'; import { Observable } from 'rxjs'; import { Request } from

API authenticate to odoo with token

青春壹個敷衍的年華 提交于 2020-04-14 07:38:08
问题 I want to authenticate to Odoo from an express application using token. I am using odoo-xmlrpc node module to connect Odoo with my express app. Odoo requires users of the API to be authenticated before they can use any other API. And this node module provides this function const odoo = new Odoo({ url: config.odooUrl,//odoo url db: config.odooDB,//odoo db path username: "john@gmail.com", password: "john_pass123" }); odoo.connect(function(err, uid) { if (err) { errors.auth = "invalid

Dynamic locals unavailable with Pug and Parcel

只愿长相守 提交于 2020-04-13 18:04:38
问题 I have an Express app using Pug templates and Parcel for my bundler. According to the Parcel docs, I can have a config file that stores my locals pug.config.js , however, I need to dynamically add locals to my templates at runtime. Is it possible to do this? Here are my files: index.pug ... h1 #{isAuthenticated} h1 #{env} ... pug.config.js module.exports = { locals: { env: process.env.NODE_ENV } } app.js const Bundler = require('parcel-bundler') const bundler = new Bundler(path.resolve(_

Dynamic locals unavailable with Pug and Parcel

独自空忆成欢 提交于 2020-04-13 18:03:32
问题 I have an Express app using Pug templates and Parcel for my bundler. According to the Parcel docs, I can have a config file that stores my locals pug.config.js , however, I need to dynamically add locals to my templates at runtime. Is it possible to do this? Here are my files: index.pug ... h1 #{isAuthenticated} h1 #{env} ... pug.config.js module.exports = { locals: { env: process.env.NODE_ENV } } app.js const Bundler = require('parcel-bundler') const bundler = new Bundler(path.resolve(_

Nodejs Express implicit middleware applied to all routes?

强颜欢笑 提交于 2020-04-13 07:58:32
问题 I wanted to know if Express would let me create a route middleware that would be called by default without me explicitly placing it on the app.get() arg list? // NodeJS newb var data = { title: 'blah' }; // So I want to include this in every route function a(){ return function(req, res){ req.data = data; }; }; app.get('/', function(req, res) { res.render('index', { title: req.data.title }); }; I understand I can do app.set('data', data) and access it via req.app.settings.data in the route.