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

http-node-routing

v1.0.24

Published

Node simple and agnostic backend lib created with http and typescript

Downloads

20

Readme

http-node-routing

This project was motivated by the will of understanding how things work. Im mainly using node http module to provide a router to handle HTTPS requests and responses. On future versions i will use a generic entity that can peform these operations on a POSTGRES database. It should be used mainly for educational propurses. Currently has support for postgresql

Technologies used

My Skills

Steps

1 - Installation

install

npm install http-node-routing

install dotenv

npm install dotenv

inside the file that you instance the server

import dotenv from 'dotenv';
dotenv.config();

1 - Config your env variables

create an .env file with the port variable on the root of the project

2 - Simple usage example

check folder examples for the basic and the examples that persists data into the database

src/examples

import router from 'http-node-routing'

const port = process.env.PORT || 3000;

const app = router()

app.listen(port, () => console.log(`listening on ${port}`))
app.get('/', (req, res) => {
	res.send('Hello World')
})
app.post('/users', (req, res) => {
	const user = req.body
	res.send(user)
})

Usage with postgres

1 - Start your postgres server

2 - Add the port that the server is running into the database key attribute from connection object

2 - Pass the table that you will perform the CRUD operations on the routes address

Disclaimer: I have added only SELECT and INSERT operations for now

import dotenv from 'dotenv';

import { databaseFunctions } from 'src/connection';

import { createNodeRouter } from '../../nodeRouter';
dotenv.config();

const port = process.env.PORT || 3000;

const app = createNodeRouter();

const connection = {
	user: process.env.PG_USER,
	host: process.env.HOST,
	password: process.env.PASSWORD,
	database: process.env.DATABASE,
	port: process.env.DB_PORT,
};

const { connectDb, getAllRegistersFromTable, insertIntoTable } =
	await databaseFunctions(connection);

app.listen(port, () => console.log(`listening on ${port}`));

connectDb();

app.get('/users', async (req, res) => {
	const registers = await getAllRegistersFromTable('users');
	res.send(registers);
});


app.post('/users', (req, res) => {
	const { email, password } = req.body!;
	const columns = ['email', 'password'];
	const valuesToInsert = [email, password];
	insertIntoTable('users', columns, valuesToInsert, res);
});

Clone the repo

git clone https://github.com/rpajf/http-node-routing

run for the basic example:

npm run start:basic

run for the persisting into postgres example:

npm run start:db

Support for other databases rather than postgres

Im implementing support for sqlite3 and mysql

How to contribute?

1 - Implement other methods for the CRUD operations on the Postgres databse

2 - Add more tests to the library routing

still in progress...

next steps:

  • Handle the req.params and req.query
  • Creating the connection with databases (postgres and mysql)