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

@ricardofuzeto/ws-boot

v0.1.0

Published

Web service boot library

Downloads

23

Readme

Warning note

This library is still under development. We do not recommend using it yet since its features and/or interfaces might change in a nightly basis.

Also, it has not been tested properly yet. Test cases are still being designed as the library evolves, so its stability can't be guaranteed for now.

If you still want to use it, consider checking this library's behavior when debugging your project.

About

Re-implementation of Express.js APIs, providing a simplified and further automatized usage, allowing developers to create web services much faster and with the same personalization levels.

Setup

This library uses @ricardofuzeto/ws-core underneath. Because of this, it is mandatory to have a file application.json in your project's root, or the application will throw an error during startup.

For ws-boot, it is expected that such JSON file contains a boot property, where all ws-boot configuration will be. It should look like this:

// ...config data
  "boot": { /* ws-boot properties */ },
// ...config data

The following table shows all configuration fields that can be placed inside the application.json file and that will be recognized by ws-boot:

| field | type | default | description | | ----- | :--: | :-----: | ----------- | | port | number | 4000 | Port that Express's application will listen to. You can also use any environment variable you want, just set this field with "process.env.YOUR_ENVIRONMENT_VARIABLE_NAME" | | bodyType | string | "json" | Parser middleware type that will be applied to Express's request bodies. Accepted values: "json", "raw", "text" and "urlencoded". | | cors | object | {} | CORS custom configuration to be applied to the Express application. For further information, see CORS |

Booting the server

To boot your Express application via ws-boot, just add the following code:

const wsBoot = require('@ricardofuzeto/ws-boot');

wsBoot.init();

This will create an Express application, add all configurations previously defined and start it, 100% transparent to you. Also, you will see on console all configurations used to create the application.

Routes

Mapping new routes

To map a new route in your application, just import ws-boot and map directly from it:

wsBoot.get('/route1', (req, res) => {});
wsBoot.get('/route2', { options }, (req, res) => {});

This mapping augments what Express.js does, adding a log message for every mapped resource, allowing developers to know exactly what routes were mapped. Also, you can note the options object, which is an optional second argument. You can define custom options for a route, according to your needs. Check the section Routes options for further information.

Supported HTTP methods

ws-boot does not support all HTTP methods. However, it does give enough support for a subset that satisfies the needs of almost all web service projects. Are the supported methods: DELETE, GET, PATCH, POST and PUT.

You can also use the ALL mapping from Express, but that is provided only for compatibility and flexibility purposes, and should be used only when absolutely no other method (even those in Express) is enough for what you need.

Routes Options

As mentioned before, to add custom options to a route, you just have to pass an object as a second argument of the mapping function, like this:

wsBoot.get('/route1', { options }, (req, res) => {});

The options object currently support the following values:

| option | type | default | description | | ----- | :--: | :-----: | ----------- | | paginated | boolean | false | When set to true, the route's response will be paginated. ws-boot will only split returned data into pages, and handle the requested page via request's query field page | | pageSize | number | 20 | Amount of results per page, when route's response is paginated |

Contributors

Ricardo Fuzeto (email): idea conception and initial development stages