Below you will find pages that utilize the taxonomy term “javascript”
Posts
How to connect your ExpressJS app with Postgres using Knex
Note: I’ve created a video for this tutorial if you’d like to check that out here. Also, the supporting code for the same can be found here
Express is one of the most popular JavaScript framework for building backend APIs and Postgres is a really popular relational database. How do we connect the two?
If you look at the official documentation for Express, you’ll see the section like this:
var pgp = require('pg-promise')(/* options */) var db = pgp('postgres://username:password@host:port/database') db.
Posts
Cloning an object in JavaScript and avoiding Gotchas
If you’re a JavaScript developer, you must have come across scenarios where you need to clone an object. How do you do it? In this article we will cover various approaches to clone an object in JavaScript and their shortcomings and finally talk about the most reliable way to make a deep copy (clone) of an object in JavaScript.
Let us consider that our object to be cloned is this:
Posts
How to add third party scripts & inline scripts in your Nuxt.js app?
Problem statement Let’s say you have created a Nuxt app and one day your client or your boss asks you to add some snippet of code to every page of the site for analytics purposes. For example:
<!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-111111111-1"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-111111111-1'); </script> Solution Open your nuxt.config.js file and update the head section as follows:
Posts
How to add authentication to your universal Nuxt app using nuxt/auth module?
Recently I was working on a Nuxt.js app and had to add authentication to it. First thing I thought was to use vuex to store two fields in a state:
isLoggedIn: a boolean representing whether user is logged in or not loggedInUser: an object containing the user details for the session that we get from server And then I added a middleware on pages where I wanted to restrict access to logged in users only.
Posts
How to read or modify spreadsheets from Google Sheets using Node.js ?
First of all, a brief overview of our use case. Let’s say I have a spreadsheet on Google Sheets which is not public and I want to be able to read/modify programmatically through some batch process running on my local machine or some server. This is something I had to do recently with a Node.js application and I found the authentication part a bit tricky to understand. So I thought of sharing my solution and I hope it helps someone in need.
Posts
Node.js AWS SDK: How to list all the keys of a large S3 bucket?
Let’s say you have a big S3 bucket with several thousand files. Now, you need to list all the keys in that bucket in your Node.js script. The AWS SDK for Node.js provides a method listObjects but that provides only 1000 keys in one API call. It does however, also send a flag IsTruncated to indicate whether the result was truncated or not. If the response contains IsTruncated as true, then it means you need to call the listObjects again, but this time, you need to pass a Marker in your parameters which tells AWS: