Skip to content

Instantly share code, notes, and snippets.

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

Eric Bishard httpJunkie

🏠
Working from home
View GitHub Profile
@httpJunkie
httpJunkie / get-started-docker-mongo-express-mongoose.md
Created February 6, 2020 17:01
Get started with Docker, Mongo, Express, and Mongoose
  1. pull the official image:
docker pull mongo

optionally pull by version:

docker pull mongo:4.2.3
@httpJunkie
httpJunkie / get-started-docker-mongo.md
Last active February 6, 2020 17:02
Get started with Docker and Mongo
  1. pull the official image:
docker pull mongo

optionally pull by version:

docker pull mongo:4.2.3
@httpJunkie
httpJunkie / 04-read.js
Last active February 27, 2020 19:49
Step 04 : Read docs from Couchbase Server with NodeJS SDK
require('dotenv').config()
const { user, pass } = process.env
const fs = require('fs')
const couchbase = require('couchbase');
const cluster = new couchbase.Cluster('couchbase://localhost', { username: user, password: pass })
const bucket = cluster.bucket('events')
let statement = "SELECT * FROM `events` WHERE category='JavaScript' AND type='event'"
new Promise((resolve, reject) => {
@httpJunkie
httpJunkie / 03-index.js
Last active February 4, 2020 12:31
Step 03: Insert category index in Couchbase Server with NodeJS SDK
require('dotenv').config()
const { user, pass } = process.env
const couchbase = require('couchbase');
const cluster = new couchbase.Cluster('couchbase://localhost',{username: user, password: pass})
const bucket = cluster.bucket('events')
let statement = "CREATE INDEX adv_category_type ON `events`(`category`) WHERE `type` = 'event'"
new Promise((resolve, reject) => {
@httpJunkie
httpJunkie / 02-index.js
Last active February 4, 2020 12:30
Step 02 : Insert primary index in Couchbase Server with NodeJS SDK
require('dotenv').config()
const { user, pass } = process.env
const couchbase = require('couchbase');
const cluster = new couchbase.Cluster('couchbase://localhost',{username: user, password: pass})
const bucket = cluster.bucket('events')
let statement = "CREATE PRIMARY INDEX ON `events`"
new Promise((resolve, reject) => {
@httpJunkie
httpJunkie / 01-upsert.js
Last active February 4, 2020 12:27
Step 01 : Upsert documents to Couchbase Server with NodeJS SDK
require('dotenv').config()
const { user, pass } = process.env
const faker = require('faker')
const couchbase = require('couchbase')
const cluster = new couchbase.Cluster('couchbase://localhost', { username: user, password: pass })
const bucket = cluster.bucket('events')
const collection = bucket.defaultCollection()
/*
@httpJunkie
httpJunkie / node_sdk_new_user.md
Last active February 7, 2020 12:33
Steps to install Couchbase, insert docs, insert index and read documents
  1. docker pull couchbase

  2. git clone https://github.com/httpJunkie/couchbase-server-lt && cd couchbase-server-lt && chmod +x configure.sh

  3. docker build -t couchbase-server-lt .

  4. docker run -d -p 8091-8094:8091-8094 -p 11210:11210 -e CB_ADMIN_USER=Administrator -e CB_ADMIN_PASS=password -e CB_BUCKET=conference-data -e CB_BUCKET_PASS= --name cbs1 couchbase-server-lt

At this point, we can visit localhost:8091 and login with Administrator and password.
We should have 1 server, 1 node, 1 bucket named conference-data!

@httpJunkie
httpJunkie / ExpressGraphQL_Server.js
Created January 13, 2020 18:59
Couchbase V2 / V3 Version Toggle
const express = require('express')
const graphqlHTTP = require('express-graphql')
const { buildSchema } = require('graphql')
const couchbase = require('couchbase')
const pjson = require('./package.json')
const cbMajorVersion = Number(pjson.dependencies.couchbase.match(/\d/))
const app = express()
@httpJunkie
httpJunkie / withApolloProvider.js
Created December 22, 2019 15:55
Higher Order Component to wrap component with an Apollo GraphQL Client provider
import React from 'react'
import ApolloClient from 'apollo-boost'
import { ApolloProvider } from '@apollo/react-hooks'
const withApolloProvider = (WrappedComponent, graphqlEndpoint) => {
const apolloClient = new ApolloClient({
uri: graphqlEndpoint,
})
return (props) => (
@httpJunkie
httpJunkie / useFecthWithUrl.js
Created November 5, 2019 19:25
useFetchWithUrl
function useFetch (url) {
const [loading, setLoading] = React.useState(true)
const [data, setData] = React.useState(null)
const [error, setError] = React.useState(null)
React.useEffect(() => {
setLoading(true)
fetch(url)
.then(res => res.json())