Proxying npm packages using Nexus

In this post, you will learn how to use your Nexus npm proxy repository as a proxy for your node js project’s npm packages. You also learn how to concfigure npmrc for proxying npm packages from Nexus. Advertisements Nexus is a repository manager that helps in managing your project’s dependencies, artifacts & metadata, docker images, … Read more

Validating request in Express using express-validator

In this article you will learn how to validate your payload coming from a POST request for an Express API using express-validator. Learn how to validate any data coming in as input to your Express endpoints. Express Validator is an npm package that helps developers to validate the incoming requests to an API build in Express in … Read more

Python code snippet – How to add captcha in django forms

This is simple: 1. Install the django-recaptcha plugin and follow the instructions. You will need the following vars and classes: RECAPTCHA_KEY_PUBLIC = ‘public-key’RECAPTCHA_KEY_PRIVATE = ‘private-key’NOCAPTCHA = True Now you’re ready to add the captcha to your form: from django import formsfrom django.conf import settingsfrom captcha.fields import ReCaptchaFieldclass ReCAPTCHAForm(forms.Form): captcha = ReCaptchaField() That’s all there is to it!

How to find duplicate documents in a MongoDB collection?

In this post we will show you how to find duplicate documents in your existing database using MongoDB’s aggregation pipeline. Let’s take a sample employees collection for this post. I’ve inserted the following documents into the employees collection. > db.employees.insertOne({employeeId: 1, employeeName: “Anand”}) { “acknowledged” : true, “insertedId” : ObjectId(“5f2cfbcf0694cb7ba344f46b”) } > db.employees.insertOne({employeeId: 2, employeeName: “Wayne”}) { “acknowledged” : … Read more

Update if exists, insert if it doesn’t exist – How to do Upsert in Mongoose?

To find a document and update it using Mongoose, you can use the findOneAndUpdate schema method. As the name implies, findOneAndUpdate() filter the document first that matches a given filter, applies an update, and returns the document.  Roles.findOneAndUpdate({role:req.params.role},{modules: req.body.modules}); But what if the document that is to be updated doesn’t exist? You can insert it as a new document, … Read more