# http-node-routing

> Node simple and agnostic backend lib created with http and typescript

Latest version **1.0.24** (published 2023-08-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install http-node-routing
pnpm add http-node-routing
yarn add http-node-routing
bun add http-node-routing
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.24 |
| Published | 2023-08-24 |
| First published | 2023-07-22 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=14.15.0 |
| Dependencies | 4 |
| Unpacked size | 45.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Raphael Portela |
| Maintainers | rpajf |
| Keywords | node, http, rest |

## Links

- npm: https://www.npmjs.com/package/http-node-routing
- Repository: https://github.com/rpajf/http-node-routing
- Homepage: https://github.com/rpajf/http-node-routing#readme
- Issues: https://github.com/rpajf/http-node-routing/issues
- npm.io page: https://npm.io/package/http-node-routing

## Dependencies (4)

- [pg](https://npm.io/package/pg.md) ^8.11.2
- [mysql](https://npm.io/package/mysql.md) ^2.18.1
- [dotenv](https://npm.io/package/dotenv.md) ^16.3.1
- [methods](https://npm.io/package/methods.md) ^1.1.2

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 1.0.24 (latest) — 2023-08-24
- 1.0.23 — 2023-08-24
- 1.0.22 — 2023-08-24
- 1.0.21 — 2023-08-24
- 1.0.20 — 2023-08-24
- 1.0.19 — 2023-08-24
- 1.0.18 — 2023-08-24
- 1.0.17 — 2023-08-16
- 1.0.16 — 2023-08-10
- 1.0.15 — 2023-08-10
- 1.0.14 — 2023-08-09
- 1.0.12 — 2023-08-09
- 1.0.11 — 2023-08-09
- 1.0.10 — 2023-08-03
- 1.0.9 — 2023-08-02
- … 8 more at https://npm.io/package/http-node-routing/versions

## 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](https://skillicons.dev/icons?i=typescript,nodejs,vscode&theme=dark)](https://skillicons.dev)

## Steps
### 1 - Installation
install 
```javascript
npm install http-node-routing
```
install dotenv
```javascript
npm install dotenv
```
inside the file that you instance the server
```javascript
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
```javascript
src/examples
```
```javascript

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

```javascript
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
```javascript
git clone https://github.com/rpajf/http-node-routing
```
run for the basic example:
```javascript
npm run start:basic
```

run for the persisting into postgres example:
```javascript
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)

---
_Source: https://npm.io/package/http-node-routing · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
