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

fastnet

v0.1.8

Published

A fast and easy web framework for nodejs

Downloads

5

Readme

Commitizen friendly jest ESLint Husky TypeScript Open Source? Yes!

FastNet - A Minimalistic Node.js Web Framework

FastNet is a lightweight and easy-to-use Node.js web framework designed to be very minimal. With a focus on simplicity, FastNet APIs have the same signature as Express.

Features

  • Simplicity: FastNet is designed to be easy to use and understand
  • Routing: Only In app routing feature.
  • Middleware Support: Easily integrate middleware functions for customizing request and response handling.
  • JSON Body Parsing: Parse JSON request bodies with built-in support for handling incoming data.
  • HTTP Methods: Support for common HTTP methods including GET, POST, PUT, and DELETE.
  • Flexibility: It easy to modifiy because its very minimal.

Installation

To get started with FastNet, install it using npm:

npm install fastnet

Usage

// Import FastNet and necessary types
import FastNet, { Request, Response } from 'fastnet';

// Create an instance of FastNet
const app = new FastNet();

// Define a sample route
app.get('/hello', (req: Request, res: Response) => {
  res.send('Hello, FastNet!');
});

// Start the server
const PORT = 3000;
app.listen(PORT, () => {
  console.log(`Server is running on http://localhost:${PORT}`);
});

Reference


Request Object

The Request object is designed to encapsulate and provide convenient access to properties and methods of an HTTP request represented by the IncomingMessage class from the "http" module. This documentation outlines the various functionalities provided by the Request class.

Constructor

Request(req: IncomingMessage)

Creates a new Request instance with the provided IncomingMessage object representing the HTTP request.

Properties

header

  • Description: Gets or sets the headers of the request.
  • Getter: Returns the headers property of the req object.
  • Setter: Sets the value of the headers property in the req object to the provided value.

url

  • Description: Gets the URL of the current request.
  • Getter: Returns the url property of the req object.

method

  • Description: Gets or sets the HTTP method of the request.
  • Getter: Returns the HTTP method of the request object or an empty string if not defined.
  • Setter: Sets the value of the "method" property in the req object to the provided value if it is a string.

body

  • Description: Asynchronously retrieves and parses the JSON body of an HTTP request.
  • Getter: Returns a Promise that resolves with the parsed JSON body.

path

  • Description: Gets or sets the pathname of the requested URL.
  • Getter: Returns the pathname property of the parsed URL from the req object or an empty string if not available.
  • Setter: Sets the path of a URL if it is different from the current path.

params

  • Description: Gets or sets the parameters of the request.
  • Getter: Returns the params property of the req object.
  • Setter: Sets the value of the params property in the req object to the provided value.

Response Object

The Response object is designed to encapsulate and provide convenient methods for handling the server's HTTP response represented by the ServerResponse class from the "http" module. This documentation outlines the various functionalities provided by the Response class.

Constructor

Response(res: ServerResponse)

Creates a new Response instance with the provided ServerResponse object representing the HTTP response.

Properties

socket

  • Description: Gets the underlying socket associated with the response.
  • Getter: Returns the socket property of the res object.

status

  • Description: Gets or sets the HTTP status code of the response.
  • Getter: Returns the status code of the response.
  • Setter: Sets the HTTP status code of the response to the provided value.

Methods

send(data: any)

  • Description: Sends data as the response body.
  • Parameters:
    • data (any): The data to be sent as the response body.
  • Behavior:
    • If data is an object, it will be converted to JSON and sent with the "application/json" content type.
    • If data is a string, it will be sent with the "text" content type.
    • The response headers are set accordingly.
    • The response is ended after sending the data.

Example of Todo Application

import FastNet, { Request, Response } from 'fastnet'

const app = new FastNet();

const PORT = 3000;

let todos = [
	{ id: 1, text: "Learn Node.js", done: false },
	{ id: 2, text: "Build a TODO app", done: false }
];

// Get all todos
app.get("/todos", async (req: Request, res: Response) => {
	res.send(todos);
});

// Get a specific todo by ID
app.get("/todos/:id", async (req: Request, res: Response) => {
	const todoId = parseInt(req.params.id);	
	const todo = todos.find((t) => t.id === todoId);

	if (todo) {
		res.send(todo);
	} else {
		res.send({ error: "Todo not found" });
	}
});

// Create a new todo
app.post("/todos", async (req: Request, res: Response) => {
	const { text } = (await req.body) as any;
	const newTodo = {
		id: todos.length + 1,
		text,
		done: false
	};
	todos.push(newTodo);
	res.send(newTodo);
});

// Update a todo
app.put("/todos/:id", async (req: Request, res: Response) => {
	const todoId = parseInt(req.params.id);
	const { text } = (await req.body) as any;
	const todo = todos.find((t) => t.id === todoId);

	if (todo) {
		todo.text = text;
		res.send(todo);
	} else {
		res.send({ error: "Todo not found" });
	}
});

// Delete a todo
app.delete("/todos/:id", (req: Request, res: Response) => {
	const todoId = parseInt(req.params.id);
	todos = todos.filter((t) => t.id !== todoId);
	res.send({ message: "Todo deleted successfully" });
});

app.listen(PORT, () => {
	console.log(`Server is running on http://localhost:${PORT}`);
});

Contributing

Contributions are welcome! There is a need for a lot of improvement to this because it is very minimal. Please open an issue or submit a pull request