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

claimyr-presidium

v0.18.5

Published

A library for creating web services

Downloads

3

Readme

Presidium

Node.js CI codecov npm version

A library for creating web services.

Handle Http

const { HttpServer, Http } = require('presidium')

new HttpServer((request, response) => {
  response.writeHead(200, { 'Content-Type': 'application/json' })
  response.write(JSON.stringify({ greeting: 'Hello World' }))
  response.end()
}).listen(3000)

const http = new Http('http://localhost:3000/')

http.get('/')
  .then(response => response.json())
  .then(console.log) // { greeting: 'Hello World' }

Handle WebSocket

const { WebSocketServer, WebSocket } = require('presidium')

new WebSocketServer(socket => {
  socket.on('message', message => {
    console.log('Got message:', message)
  })
  socket.on('close', () => {
    console.log('Socket closed')
  })
}).listen(1337)


const socket = new WebSocket('ws://localhost:1337/')
socket.addEventListener('open', function (event) {
  socket.send('Hello Server!')
})
socket.addEventListener('message', function (event) {
  console.log('Message from server:', event.data)
})

CRUD and Query DynamoDB

const { DynamoTable, DynamoIndex } = require('presidium')

const awsCreds = {
  accessKeyId: process.env.AWS_ACCESS_KEY_ID,
  secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
  region: process.env.AWS_REGION,
}

;(async function() {
  const myTable = new DynamoTable({
    name: 'my-table',
    key: [{ id: 'string' }],
    ...awsCreds,
  })
  const myIndex = new DynamoIndex({
    table: 'my-table',
    key: [{ name: 'string' }, { age: 'number' }],
    ...awsCreds,
  })
  const myStream = new DynamoStream({
    table: 'my-table',
    ...awsCreds,
  })

  await myTable.ready
  await myIndex.ready
  await myStream.ready

  await myTable.putItem({ id: '1', name: 'George' })
  await myTable.updateItem({ id: '1' }, { age: 32 })
  console.log(
    await myTable.getItem({ id: '1' }),
  ) // { Item: { id: { S: '1' }, ... } }

  console.log(
    await myIndex.query('name = :name AND age < :age', {
      name: 'George',
      age: 33,
    }),
  ) // [{ Items: [{ id: { S: '1' }, ... }, ...] }]

  for await (const record of myStream) {
    console.log(record) // { dynamodb: { NewImage: {...}, OldImage: {...} }, ... }
  }
})()

Consume Kinesis Streams

const { KinesisStream } = require('presidium')

const awsCreds = {
  accessKeyId: process.env.AWS_ACCESS_KEY_ID,
  secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
  region: process.env.AWS_REGION,
}

const myStream = new KinesisStream({
  name: 'my-stream',
  ...awsCreds,
})

;(async function() {
  await myStream.ready

  await myStream.putRecord('hey')
  await myStream.putRecord('hey')
  await myStream.putRecord('hey')

  for await (const item of myStream) {
    console.log(item) /*
    {
      SequenceNumber: '49614...',
      ApproximateArrivalTimestamp: 2021-01-12T16:01:24.432Z,
      Data: <Buffer ...>, // hey
      PartitionKey: 'hey',
    }
    {
      SequenceNumber: '...',
      SequenceNumber: '49614...',
      ApproximateArrivalTimestamp: 2021-01-12T16:01:24.432Z,
      Data: <Buffer ...>, // hey
      PartitionKey: 'hey',
    }
    {
      SequenceNumber: '49614...',
      ApproximateArrivalTimestamp: 2021-01-12T16:01:24.432Z,
      Data: <Buffer ...>, // hey
      PartitionKey: 'hey',
    }
    */
  }
})

Upload to S3

const { S3Bucket } = require('presidium')

const awsCreds = {
  accessKeyId: process.env.AWS_ACCESS_KEY_ID,
  secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
  region: process.env.AWS_REGION,
}

const myBucket = new S3Bucket({
  name: 'my-bucket',
  ...awsCreds,
})

;(async function () {
  await myBucket.ready

  await myBucket.putObject('some-key', '{"hello":"world"}', {
    ContentType: 'application/json',
  })
  console.log(
    await myBucket.getObject('some-key'),
  ) // { Etag: ..., Body: '{"hello":"world"}', ContentType: 'application/json' }
  await myBucket.deleteAllObjects()
  await myBucket.delete()
})()

Build and Push Docker Images

Stop using --build-arg for that npm token

const { DockerImage } = require('presidium')

const myImage = new DockerImage('my-app:1.0.0')

const buildStream = myImage.build(__dirname, {
  ignore: ['.github', 'node_modules'],
  archive: {
    Dockerfile: `
FROM node:15-alpine
WORKDIR /opt
COPY . .
RUN echo //registry.npmjs.org/:_authToken=${myNpmToken} > .npmrc \
  && npm i \
  && rm .npmrc
  && rm Dockerfile
EXPOSE 8080
CMD ["npm", "start"]
    `,
  },
})

buildStream.on('end', () => {
  const pushStream = myImage.push('my-registry.io')
  pushStream.pipe(process.stdout)
})
buildStream.pipe(process.stdout)

Execute Docker Containers

const { DockerContainer } = require('presidium')

const container = new DockerContainer({
  image: 'node:15-alpine',
  env: { FOO: 'foo' },
  cmd: ['node', '-e', 'console.log(process.env.FOO)'],
  rm: true,
})

container.run().pipe(process.stdout) // foo

Deploy Docker Swarm Services

const { DockerSwarm, DockerService } = require('presidium')

;(async function() {
  const mySwarm = new DockerSwarm('eth0:2377')
  await mySwarm.ready // initiated new docker swarm

  const myService = new DockerService({
    name: 'my-service',
    image: 'nginx:1.19',
    publish: { 80: 80 },
    healthCheck: ['curl', '[::1]'],
    replicas: 5,
  })
  await myService.ready // new nginx service is up running
})()