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

@shinerzoch/server

v1.0.10020

Published

All in one server, supports. Mysql, Local, and Mongodb more coming soon.

Downloads

24

Readme

Getting Started

To get started please run the following commands from your project directory. If you havent done so yet please make sure you have NodeJS installed. Please make sure you init your project by using the command below.

npm init --yes

Now in order to get started using our package as your server. Please run the following command.

npm i @shinerzoch/server

This command will install our package inside your application. This will allow you to use the below coding to get started.

Javascript NodeJS Module

// index.mjs

import Server from '../serverLibrary/index.js';
const port = 8080;

    // App logic goes here...    

Server.start(port);

Javascript NodeJS

// index.js

const Server = require('../serverLibrary/index.js');

(async () => {
    const port = 8080;
    
        // App logic goes here...   

    Server.start(port);
})();

Table Of Contents

Database

Functions

Query Find One Find Many Find By IDs Save Update Delete Count Clear

Auto Routes

Cookies

Session

Server Side Events

Web Sockets

Database Module

Database Functions

Query Find One Find Many Find By IDs Save Update Delete Count Clear

You can set the default database by setting Server.db = DatabaseInstance. This is not a requirement, but it is recommended if you plan on using the database as your main projects database.

Database Create Mysql Instance

const db = await Server.Database.create("mysql", {
    modelsPath: "models",
    name: "default",
    host: "localhost",
    port: 3306,
    username: "testing",
    password: "testing",
    database: "testing",
});

Database Create Local Instance

This is a database that is completely file based and the contents are stored within your project. or any directory of choosing.

const db = await Server.Database.create("local", {
    name: "default", // Must be unqiue if not default.
    modelsPath: "models"
});

Database Query

Executes a raw SQL query.

const rawData = await Server.db.query(`SELECT * FROM USERS`);

Database Find One

Finds the first entity that matches some id or find options.

const response = await Server.db.table("users").findOne({
    where: {
        username: "test"
    }
})

Database Find Many

Finds entities that match given options.

const userData = await Server.db.table("users").find({ username: "admin" });

Database Find By IDs

Finds multiple entities by id.

const count = await Server.db.table("users").findByIds([1, 2, 3]);

Database save

Saves a given entity or array of entities. If the entity already exists in the database, then it's updated. If the entity does not exist in the database yet, it's inserted. It saves all given entities in a single transaction. Also supports partial updating since all undefined properties are skipped. In order to make a value NULL, you must manually set the property to equal null.

const userID = await Server.db.table("users").save({ username: "admin", password: "admin" });

const userIDs = await Server.db.table("users").save([
    { username: "admin", password: "admin" },
    { username: "test", password: "test" }
]);

Database update

Partially updates entity by a given update options or entity id.

const newData = await Server.db.table("users").update({ id: 1 }, { username: "superadmin" });

const newData = await Server.db.table("users").update(1, { username: "superadmin" });

Database delete

Deletes entities by entity id, ids or given conditions:

await Server.db.table("users").delete(1);
await Server.db.table("users").delete([1, 2, 3]);
await Server.db.table("users").delete({ id: 1 });
await Server.db.table("users").delete([{ id: 1 }, { username: "test" }]);

Database count

Counts entities that match given options. Useful for pagination.

const count = await Server.db.table("users").count({ active: true });

Database clear

Clears all the data from the given table (truncates/drops it).

const count = await Server.db.table("users").clear();

Auto Routes Module

This module is created to auto generate routes based of a directory.

await Server.AutoRoutes.install({
    path: "routes" // Optional Defaults to "routes", you can use something like "client/routes".
});

Cookies Module

This module allows our server and you to interact with cookies on the clients browser.

await Server.Cookies.install();

Session Module

This module requires Cookies module to be enabled. This module created a session storage for you to use.

await Server.Session.install({
    secret: "somethingrandom"
});

Server Side Events Module

This module adds Server Side Events to the servers router.

await Server.ServerSideEvents.install();

Web Sockets Module

This module adds Web Sockets to the servers router.

await Server.WebSockets.install();