Skip to content

Instantly share code, notes, and snippets.

View abhishekr700's full-sized avatar
🏠
Working from home

Abhishek Ranjan abhishekr700

🏠
Working from home
  • Google
  • Bengaluru, India
  • 19:56 (UTC +05:30)
View GitHub Profile

Sequelize Querying Basics for newbies

Users = Table variable exported from sequelize

"options" object

=>"options" object is same for all find-like queries

Selective attributes =>

Users.findById(req.user.id,{
        attributes: ["id","username","name"]`

Node.js use MongoDB using Mongoose module

( Each model in separate file )

mongo.js

This file holds connection to DB & also creates schema by importing them from other files.
//Import the mongoose module
const mongoose = require("mongoose");

//Import DB Models

Terminate an application

process.exit([code])
Ends the process with the specified code.
If omitted, exit uses the 'success' code 0.
To exit with a 'failure' code: process.exit(1);
The shell that executed node should see the exit code as 1.


Check if a file exists

Scheduling Tasks in Node.JS

With Persistence across server reboots

** If task deadline over while server is off, task will be executed as soon as server starts. ** Stores data in MongoDB..

Module: Mongo-Scheduler-More npmjs.com/package/mongo-scheduler-more

(This is a further developed version of Mongo-Scheduler with more features & updated dependencies.)

Usage :

How to do work with Javascript before Form-Submit

Sometimes we may need to place checks on the input fields before the form is submiteed. One example is that you may have a re-enter passwork field and if the types passwords are not same, you may show a error message. In such cases , this is how you can do some work before the form is submitted and also avoid the submission from happening.
Source https://stackoverflow.com/questions/8133712/execute-javascript-code-straight-before-page-submit

const express = require("express");
const session = require("express-session");
const app = express();
app.use(express.json());
app.use(express.urlencoded({
extended: true
#!/bin/bash
# Copyright (C) 2019 Abhishek Ranjan <[email protected]>
# SPDX-License-Identifier: GPL-3.0-or-later
## Usage: ./runAllCoins.sh
## Don't continue on errors
set -e

Commands for installing packages with conda cli

Google CLoud SDK

conda install -c conda-forge google-cloud-sdk
  1. conda install -c conda-forge google-cloud-sdk
  2. gcloud init
  3. It will ask you to login
  4. Select project

Install Google Cloud Vision API

conda install -c conda-forge google-cloud-vision