• This repository has been archived on 29/Mar/2022
  • Stars
    star
    674
  • Rank 64,664 (Top 2 %)
  • Language
    TypeScript
  • Created over 9 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Firebase Realtime Database Server Implementation

Project Deprecated!

This project has reached its end-of-life, and will no longer be maintained. For information about the official alternative from the Firebase team, have a look at the Firebase Local Emulators Migration Guide.

Moving forward, new features will not be added, and only security-related bugfixes will be released.

firebase-server

Firebase Web Socket Protocol Server. Useful for emulating the Firebase server in tests.

Copyright (C) 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, Uri Shaked and contributors

Build Status Coverage Status npm version

Installation

You can install firebase-server through npm:

npm install --save-dev firebase-server

or yarn:

yarn add -D firebase-server

Usage examples

const FirebaseServer = require('firebase-server');

new FirebaseServer(5000, 'localhost', {
  states: {
    CA: 'California',
    AL: 'Alabama',
    KY: 'Kentucky'
  }
});

After running this server, you can create a Firebase client instance that connects to it:

import * as firebase from 'firebase/app';
import 'firebase/database';

const app = firebase.initializeApp({
  databaseURL: `ws://localhost:5000`,
});

app.database().ref().on('value', (snap) => {
  console.log('Got value: ', snap.val());
});

Setup with global test hooks

In the case of Mocha, you'd do something like the example below.

// => e.g. global-test-hooks.js
const FirebaseServer = require("firebase-server");

let firebaseServer;

before(() => {
   firebaseServer = new FirebaseServer(5000, "localhost");
});

after(async () => {
   await firebaseServer.close();
});
// => require the file with the --file flag
mocha --file /path/to/global-test-hooks.js

Command Line Interface

This package installs a CLI script called firebase-server. It can be installed locally or globally. If installed locally, use the following path to start the server: ./node_modules/.bin/firebase-server

The following command will start a firebase server on port 5555:

firebase-server -p 5555

... and with a specified bind IP address:

firebase-server -p 5555 -a 0.0.0.0

To bootstrap the server with some data you can use the -d,--data or the -f,--file option. Note: The file option will override the data option.

firebase-server -d '{"foo": "bar"}'

firebase-server -f ./path/to/data.json

To load Firebase Security rules upon startup you can use the -r,--rules option.

firebase-server -r ./path/to/rules.json

You can also specify a shared client auth token secret with the -s argument:

firebase-server -s some-shared-secret

To enable REST API, run:

firebase-server -e

Note: currently REST API does not implement authentication or authorization.

To daemonize the server process, use:

firebase-server -b

To write the PID to a file, use:

firebase-server --pid /var/run/firebase-server.pid

_Note: PID file can be written with or without daemonization, and is NOT written by default when daemonizing.

For more information, run:

firebase-server -h

FirebaseServer methods

The constructor signature is FirebaseServer(portOrOptions, name, data) where portOrOptions is either a port number or a WebSocket.Server options object with either port or server set. name is optional and is just used to report the server name to clients. data is the initial contents of the database.

If you want the server to pick a free port for you, simply use the value 0 for the port. You can then get the assigned port number by calling the getPort() method on the returned server object.

FirebaseServer instances have the following API:

  • close(): Promise - Stops the server (closes the server socket)
  • getValue() - Returns a promise that will be resolved with the current data on the server
  • exportData() - Returns a promise that will be resolved with the current data on the server, including priority values. This is similar to DataSnapshot.exportVal().
  • address() - Returns the address the server is listening on
  • port(): number - Returns the port number the server is listening on
  • setRules(rules) - Sets the security rules for the server. Uses the targaryen library for rule validation.
  • setAuthSecret(secret) - Sets the shared secret used for validating Custom Authentication Tokens.
  • setTime(timestamp) - Sets the server time. The server time is returned by ServerValue.TIMESTAMP and is also used for checking the validity of Custom Authentication Tokens.

Debug logging

This project uses the excellent debug module for logging. It is configured by setting an environment variable:

$ DEBUG=* mocha                                # log everything
$ DEBUG=firebase-server* mocha                 # log everything from firebase-server
$ DEBUG=firebase-server:token-generator mocha  # log output from specific submodule

Advanced options are available from the debug docs

License

Released under the terms of MIT License:

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

angular-moment

Moment.JS directives for Angular.JS (timeago and more)
JavaScript
2,609
star
2

ngx-moment

moment.js pipes for Angular
TypeScript
1,174
star
3

angular-spinner

Angular directive to show an animated spinner (using spin.js)
TypeScript
697
star
4

muse-js

Muse 2016 EEG Headset JavaScript Library (using Web Bluetooth)
TypeScript
267
star
5

angular-load

Dynamically load scripts and css stylesheets in your Angular.JS app
JavaScript
242
star
6

angular-iot

Internet of Things directives for Angular 2 (Led, Button, etc.)
TypeScript
95
star
7

gulp-add-src

Add more 'src' files at any point in the pipeline (gulp plugin)
JavaScript
86
star
8

web-bluetooth-polyfill

Windows 10 Web Bluetooth Polyfill
JavaScript
76
star
9

web-ar-experiment

Experimenting with WebAR
HTML
68
star
10

arduino-slack-bot

A Real Time Slack Bot for Arduino (ESP8266)
Arduino
64
star
11

win-ble-cpp

Proof of Concept - BLE on Windows (for Web Bluetooth)
C++
63
star
12

pdfium-wasm

Building PDFium for Web Assembly
Dockerfile
61
star
13

ng2-simon

Simon Game for angular2-iot
Eagle
58
star
14

bigtsquery

Search Engine for TypeScript Code using AST Queries
TypeScript
50
star
15

web-lightbulb

Smart Light Bulb Web App (using Web Bluetooth)
JavaScript
49
star
16

muse-blink

Blink detection with Muse EEG Headset + Angular demo
TypeScript
43
star
17

angular-placeholder-shim

Angular directive to make the input/textarea placeholder attribute work on all browsers.
JavaScript
41
star
18

tsquery-playground

Playground for TSQuery
TypeScript
37
star
19

muse-lsl

Muse 2016 EEG Headset LSL (NodeJS)
JavaScript
32
star
20

purple-eye

A web-bluetooth controlled one-eyed robot
C++
26
star
21

ng-beacon

ng-beacon - Smart JavaScript Beacon shaped after the Angular logo
Eagle
24
star
22

angular2-material-build

Material Design for Angular2
JavaScript
22
star
23

angular-static-site

Static Website with Angular - Build time rendering
TypeScript
20
star
24

beat-machine

Salsa Beat Machine 5 (Next.js + Web Audio)
TypeScript
20
star
25

node-lsl

LibLSL bindings for Node.js
JavaScript
20
star
26

cinto

Python
20
star
27

awesome-web-bluetooth

Awesome list of Web Bluetooth Libraries, Demos and Resources
17
star
28

ng-lift

Automated tooling for upgrading Angular.js app to Angular
TypeScript
17
star
29

vscode-tsquery

TSQuery extension for Visual Studio Code
TypeScript
17
star
30

AndroidThingsCounter

Android Things app that uses a 7-Segment to display counter
Java
16
star
31

web-bluetooth-mock

Mock Implementation of Web Bluetooth (for tests)
TypeScript
15
star
32

aramcon-badge

Just a badge
Python
15
star
33

pdfium-wasm-example

Example of using PDFium Web Assembly build in Node.js
JavaScript
15
star
34

real-trex-runner

IRL version of Chrome Offline T-Rex game
JavaScript
13
star
35

heart-ariella

Heart-shaped flashlight PCB for Ariella
Eagle
12
star
36

java-openal

OpenAL JNA Wrappers for Java
Java
12
star
37

vr-hero-aframe

VR Hero: Invaders game with Angular + A-Frame
TypeScript
11
star
38

d3-angularjs-demo

Demo code for my talk: "Visualizing Data streams using Angular & D3.js"
JavaScript
11
star
39

TiMedia

AVFoundation wrappers for Titanium
Objective-C
11
star
40

angular-aframe-pipe

A-Frame pipe for interop with Angular
TypeScript
11
star
41

solidity-contracts

A collection of solidity contracts found on Github
JavaScript
11
star
42

webble-mip

MiP Robot Web Bluetooth App
HTML
10
star
43

circuitpython-mp3-ble

Streaming MP3 over BLE using CircuitPython and VS1053
Python
10
star
44

panda

Panda Logo PCB
Batchfile
9
star
45

angular-promises-toolkit

Extends the Angular.JS promise API with useful methods
JavaScript
9
star
46

aframe-fireball-component

Fireball component for A-Frame
JavaScript
8
star
47

love

Because branches also need some love!
8
star
48

gwt-titanium

A GWT module for Appcelerator's Titanium Platform
Java
8
star
49

t-rex-vr

VR Experiment T-Rex Game
JavaScript
8
star
50

ZlSound

Zero Latency Sound module for Titanium
Objective-C
8
star
51

nn-function-generator

Experimenting with automatic generation of TS function bodies using ANN models
TypeScript
8
star
52

ml-comments-gen

Generating source code comments with Machine Learning
TypeScript
8
star
53

tiny-simon

Simon Says game for ATTiny85
C++
8
star
54

aframe-camera-events

A-Frame helper to emit events when camera position / orientation changes
JavaScript
7
star
55

ng-beacon-app

Angular app to control ng-beacons
TypeScript
7
star
56

noble-winrt

WinRT bindings for Noble (using BLEServer.exe)
JavaScript
7
star
57

ctf-shittyaddon

Capture The Flag Shitty Addon
C++
7
star
58

typewiz-webpack-demo

Demo of using TypeWiz with WebPack
JavaScript
6
star
59

m3d-tools

Command line tools for interacting with the M3D Printer
C#
6
star
60

battery-bulb

Battery Powered Magic Blue bulb
5
star
61

angular-es6-promises

ECMAScript 6 promises for Angular.JS
JavaScript
5
star
62

trumpet-nuggets

Web MIDI Snippets created by attendees during Chrome Dev Summit 2018
TypeScript
5
star
63

web-bluetooth-mamush

Live coding Web Bluetooth, a smart light bulb, Muse EEG headset and Chrome T-Rex game with React
JavaScript
5
star
64

spinduino-js

POV Fidget spinner running JavaScript
JavaScript
5
star
65

web-bluetooth-secure-dfu

nRF5x Secure DFU over Web Bluetooth PoC
JavaScript
5
star
66

magicblue

Control Magic Blue Bulbs using Web Bluetooth
TypeScript
4
star
67

android-hello-arm

Hello world in Android ARM assembly
Batchfile
4
star
68

m3d-pro-gcodes

GCodes and Troubleshooting for the M3D Pro
4
star
69

hot-or-not

Hot or Not game for ng-beacons
TypeScript
4
star
70

elm-smart-bulb

Initial PoC of controlling a Smart Bluetooth Bulb from Elm code using Web Bluetooth
Elm
4
star
71

valentines-vr

Small VR heart-collecting game for Valentines, live-coding during a IoT Makers meetup using A-Frame
HTML
4
star
72

vr-audio-visualizer

Audio Visualization Experiment with Angular + A-Frame
TypeScript
4
star
73

bluetooth-buzzer-button

Bluetooth Smart Buzzer Button, programmable with JavaScript
JavaScript
4
star
74

ng-beacon-firmware

ng-beacon firmware builds
4
star
75

particle-mesh-broadcast

Sample code for broadcasting a message over the local mesh network using UDP
C++
3
star
76

web-midi-playground

Web MIDI Playground for Chrome Dev Summit demo
TypeScript
3
star
77

bitcoin-action-express

"Bitcoin Info" Assistant Action with TypeScript + Express
TypeScript
3
star
78

web-bluetooth-typings

Typings for Web Ble
TypeScript
3
star
79

ng-beacon-firmware-old

JavaScript Firmware for ng-beacon (based on Espruino)
Shell
3
star
80

espruino-mirror

Cast Espruino Pixl.js Display over BLE connection
TypeScript
3
star
81

doggie

A simple android watchdog application
Java
3
star
82

ng2-simon-highscore

App to display ng2-simon highscore on a TV
TypeScript
3
star
83

ac-generators

AngularConnect Generators + Protractor demo (TopCat)
JavaScript
3
star
84

t-rex-blinks

Chrome T-Rex Game controlled by eye blinks
JavaScript
3
star
85

firebase-localstorage-fix

Firebase 3.1.0 with support for disabled LocalStorage (e.g. private browsing in Safari)
JavaScript
3
star
86

iphonejava-hello-world

Hello world iPhone application written in Java!
Java
3
star
87

protractor-firebase

Utilities for interacting with Firebase within protractor tests
JavaScript
3
star
88

pi-thingy52-weather

Weather Station using Raspberry Pi, Thingy52 and HSDPA dongle
JavaScript
3
star
89

extract-java-classes

Extract all Java class definitions from the Github dataset
JavaScript
2
star
90

coronavirus-3d

Corona Virus 3D
HTML
2
star
91

ng2-topcat

Angular 2 + Firebase Cat Rating System
TypeScript
2
star
92

muse-systemjs

Muse EEG Headset + SystemJS Minimal Setup
HTML
2
star
93

vr-talk-assets

Assets for WebVR talk
TypeScript
2
star
94

solidity-downloader

Downloads a bunch of Solidity Contracts from GitHub Repos
JavaScript
2
star
95

serial-7segment-20mm

PCB + Firmware for 20mm Serial 7-Segment Display
Eagle
2
star
96

ng-pitfalls-demos

Code samples from my presenetation "Avoiding Common Pitfalls in AngularJS"
JavaScript
2
star
97

lightshow-poc

JavaScript
2
star
98

aramcon-broadcast

Broadcast MP3 Data over ESB (Enhanced ShockBurst) using nRF52840 + USB CDC
C
2
star
99

ble-pressure-sensor

Bluetooth Low Energy Pressure Sensor with Espruino
TypeScript
2
star
100

sa2015-topcat

Topcat
JavaScript
2
star