Skip to content

Instantly share code, notes, and snippets.

View miladr0's full-sized avatar
:octocat:

Milad Ranjbar miladr0

:octocat:
View GitHub Profile
PORT=3000
MONGO_USER=mongoadmin
MONGO_PASS=mongoadmin
MONGO_URI=mongodb://127.0.0.1:27017/bull_mongo
#Redis config
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
import Queue from 'bull';
import models from '../mongoose';
import opts from '../lib/redisConnection';
const hitApiQueue = new Queue('last-login', opts);
hitApiQueue.process(async (job) => {
try {
const { apiUrl } = job.data;
import Redis from 'ioredis';
const PORT = process.env.REDIS_PORT;
const HOST = process.env.REDIS_HOST;
const client = new Redis(PORT, HOST);
const subscriber = new Redis(PORT, HOST);
const opts = {
createClient(type) {
switch (type) {
import mongoose from 'mongoose';
import HitApi from './models/hitApi.model';
mongoose.Promise = Promise;
// Exit application on error
mongoose.connection.on('error', (err) => {
console.error(`MongoDB connection error: ${err}`);
process.exit(-1);
});
import mongoose from 'mongoose';
/**
* HitApi Schema
* @private
*/
const hitApiSchema = new mongoose.Schema({
api: {
type: String,
},
import express from 'express';
const app = express();
// respond with "hello world" when a GET request is made to the homepage
app.get('/', (req, res) => {
res.send('hello world');
});
app.get('/api-1', (req, res) => {
@miladr0
miladr0 / docker-compose.yml
Created October 11, 2020 09:41
define containers
version: "2"
services:
mongodb:
image: mongo
volumes:
- ./volumes/mongodata:/data/db
environment:
- MONGO_INITDB_ROOT_USERNAME=mongoadmin
- MONGO_INITDB_ROOT_PASSWORD=mongoadmin
ports:
@miladr0
miladr0 / gist:6807d4dbd0141c4f61ddb26b5f464bb1
Created January 30, 2019 23:45
Restore a Mongodb Database when using authentication
sudo mongorestore --username "YourUserName" --password "YourPassword" --authenticationDatabase "admin" --db yourdbname --drop /path/to/archive/folder/