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

serve-dot-js

v0.0.1

Published

ServeJS is a JavaScript server-side framework for building server-rendered user interfaces

Downloads

11

Readme

Serve-JS is an implementation of midnqp/frameworkless specification.

  • Its easy to write: Any who knows simple html and css is good to go, except for writing the server side logic if required means one should have knowledge of nodejs.
  • Node in HTML: Allows you write nodejs code inside html
  • Routing: It intelligently performs the routing for you. So no need to worry about url paths, except you need to customize the endpoints. As a plus, you don't have to include .html at the end of URLs requesting HTML files.
  • Usable for both http and https: Whether its http

✨ Features

  • Resuable Components: You could build encapsulated components that manage their own logic and state. This could be used to build even more complex UIs.
  • Middlewares: For more controlled routing logic e.g req.body's data validation.
  • Routing: Serve-JS does automatic routing for you even without you writing server code. It also supports dynamic routes.

📦 Installation

$ npm install serve-dot-js

🚀 Examples

Basic ServeJS server

This example demonstrates the use of ServeJS for serving files from a folder.

const app = require("serve-dot-js");
app.listen(3000, () => console.log(`Server started on port 3000`));

Default folder it reads from is Src folder. In this folder contains the html, css and javascript files to be served. But this can be overwritten using a serveJS method. See example below.

const app = require("serve-dot-js");

app.setView("Public"); // Changes the default folder for reading files from.
app.listen(3000, () => console.log(`Server started on port 3000`));

Using http/https modules

Servejs allows you the freedom and flexibility to structure your apps the way you want. See example below:

const http = require("http");
const app = require("serve-dot-js");

http.createServer(app.route)
    .listen(process.env.PORT ||  4000, () => console.log('Server is running on PORT 3000'));

Custom routes

This methods are used to assign function handlers to specific routes. Whenever the endpoint is hit and it matches the method type, the handler tied to that endpoint is called

ServeJS.prototype.get()

For GET requests.

ServeJS.prototype.post()

Adds endpoints with respective handlers for POST requests.

ServeJS.prototype.delete()

Adds endpoints for DELETE requests.

ServeJS.prototype.put()

For put requests.

ServeJS.prototype.options()

Adds endpoints for PUT requests.

▶️ Methods

route

This method handles the whole routing process. It's passed as argument to http/https createServer methods.

setView

This sets the default folder for reading files from. Note: This is used if no custom route is set.

setStatic

This sets the default folder to serve files from. This is only used when custom routes are defined and a static file e.g css, js files, etc are requested.

setLogger

This function will tell ServeJS to log request details if given a value of true. Defualt value is false. Hence, ServeJS won't log requests by default.

listen

This is a mere wrapper around http and simply starts a http server for you, given a PORT.

render

The render method is passed to the response object of routes' callbacks. res.render(fileName) will render file with fileName to the client.

send

The primary functionality of this method is to send the file a file to the client. It accepts three parameters req, res, and filePath.

use

This method is used for adding middlewares(functions) that will be called upon every request made. For a more targetted use of middlewares may be on a specific set of routes and not all routes please be sure to add it to the route definition.

json

This is a serve middleware which if assigned, will make the value of req.body in JSON format.

raw

This serve middleware will keep req.body's value in it's raw form.

text

This serve middleware returns req.body as a string.

urlencoded

This middleware will return the values of a request in url encoded form.

📕 Documentation

Not available yet: https://spiffgreen.github.io/serve-js

⚙️Issues

You have suggestions? or something you wish is added to the framework to make users experience better? We have a working issue tracker to meet the request of many. Please note that if an issue does not conform to the standard of Serve-JS it will be closed immediately.

✍️ Contributing Guide

Please read the Contributing.md file for guidelines to contribute to this project.

📜 License

Serve-JS is MIT licensed

Copyright 2021 Spiff Jekey-Green [email protected]

Copyright 2021 Muhammad Bin Zafar [email protected]