npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@elyez/gateway

v1.0.3

Published

Elyez GPS Gateway / Receiver

Downloads

5

Readme

Elyez - GPS Gateway TCP/UDP Server

build status codecov npm

Simple usage

const Elyez = require('@elyez/gateway');

const app = Elyez();
app.listen(PORT, function() {
  console.log('Server is running in %s mode port %s', app.options.mode || 'TCP', app.port );
});

Options

const options = {
  mode: 'UDP'       //default: TCP
  encoding: 'hex'   //default: UTF-8
}
const app = Elyez(options);

.listen(port, [callback])

Start server listening on given port number

app.listen(process.env.PORT || 3000);

app.listen(process.env.PORT || 3000, function() {
  console.log('Server is running in %s mode port %s', app.options.mode || 'TCP', app.port );
});

.set(key, value)

Set new custom value

app
.set('my', value)
.set('anything', 'valuable')
.listen(process.env.PORT || 3000);

Parser

Parser function to formatted GPS Data

const Concox = require('@elyez/concox');

app
.set('parser', Concox.GT06N)
.listen(process.env.PORT || 3000);

Middleware

Middleware runs in series. This is the main difference with Service described lower. Blocking functions and run in sequential mode. The order matters and data will be changed depends on the process to next middleware functions.

.use(function(socket, data, next))

const myMiddleware = (socket, data, next) => {
  socket.name = 'foo';
  const rawdata = data.raw;
  //process data further
  // ...
  
  //continue to next middleware (important!)
  next();
};

app
.set('parser', Concox.GT06N)
.use(myMiddleware)
.listen(process.env.PORT || 3000);

Provide options to middleware, suits better for database adapters;

src/middleware/database

const MongoClient = require('mongodb').MongoClient;

module.exports = (app, options) => {
  if (!app.db) {
    const url = `mongodb://${username}:${password}@localhost:27017/${database}`;
    app.db = yield MongoClient.connect(url, {poolSize: options.poolSize || 10});
  }
  
  const collection = db.collection('documents');
  
  return function(socket, data, next){
    collection.updateOne( {id: data.id}, {$set: data}, {upsert: true, safe: false}, function(err,data){
        if (err) return next(err);
        
        console.log(data);
        next();
    })
  }
}

app.js

const Elyez = require('@elyez/gateway');
const Concox = require('@elyez/concox');
const database = require('./src/middleware/database');

const app = Elyez();
app
.set('encoding', 'hex')
.set('parser', Concox.GT06N)
.use(database(app, {
    username: 'user',
    password: 'pass',
    database: 'elyez'
  })
)
.listen(process.env.PORT || 3000);

Service

Services run in parallel. Data passed to services is considered to be fixed and final.

.service(function(data, [done]))

Register service to the app

src/service/console

module.exports = (data, done) => {
    console.log(data);
    
    //optional call in the end each service
    done();
}

src/service/webhook

const request = require('request');

module.exports = (options) => {
  return function(data, next){
    request.post({url:options.url, formData: data});
  }
}

app.js

const Elyez    = require('@elyez/gateway');
const Concox   = require('@elyez/concox');
const database = require('./src/middleware/database');
const console  = require('./src/service/console');
const webhook  = require('./src/service/webhook');

const app = Elyez();
app
.set('encoding', 'hex')
.set('parser', Concox.GT06N)
.use(database(app, {
    username: 'user',
    password: 'pass',
    database: 'elyez'
  })
)
.service(console)
.service( webhook({url: 'https://my.anotherapp.com/webhook/elyez'}) )
.listen(process.env.PORT || 3000);

Events

  • connect
  • disconnect (alias end)
  • error

app.js

const Elyez    = require('@elyez/gateway');
const Concox   = require('@elyez/concox');
const console  = require('./src/service/console');

const app = Elyez();

app.on('connect', client => {
  console.log(client, 'CONNECTED');
});
app.on('disconnect', client => {
  console.log(client, 'DISCONNECTED');
});
app.on('error', err => {
  console.error('Error:', err);
});

TODO

  • Send Commands

License

The MIT License (MIT)