npm package: @luccafelipetto/easy-session
Description: A library for managing user sessions in JavaScript applications.
Author: Lucca2013
Latest version: 1.0.2

## EasySession

**Easy Session** is a library for Node.js developed to simplify and strengthen the management of sessions in your web applications.

## Introduction

The main objective of Easy Session is to abstract complexity behind the creation and validation of sessions. It implements a reliable verification system, where session IDs are stored synchronously both not in **localStorage** on the client but in a **warehouse on the server side** (supporting JSON, PostgreSQL or MySQL).

## Library Highlights:

* **Robust Security:** Guarantee the validation of sessions through verification in both layers (client and server).
* **Full Automation:** Automatically manage communication with the data bank and HTTP requirements between the frontend and the backend.
* **Architecting Flexibility:** Choose between a robust database (PostgreSQL/MySQL) or a simple JSON file to meet the needs of your project.
* **Easy Integration:** Designed to be implemented with a minimum of code, providing a direct API.

## Example

With Easy Session, configure an endpoint to create simple and direct sessions:

```js
await EasySession.DB.create(DATABASE_URL);

//usage example with express
app.post('/sessions/listenNewUsers', EasySession.AppendInfoAndReturnId( 
    { 
        type: "DB", 
        databaseUrl: DATABASE_URL 
    }
));
```

## Installation

Just run:

```bash
npm i @luccafelipetto/easy-session
```

---

## Usage Example

SQL server storage

```js
import EasySession from "@luccafelipetto/easy-session";
import dotenv from 'dotenv';
import express from "express";

dotenv.config();

const app = express();
app.use(express.json());
const DATABASE_URL = process.env.DATABASE_URL;

await EasySession.DB.create(DATABASE_URL);

app.listen(3000, () => {
    console.log('Server is running on port 3000');
});

app.get('/', (req, res) => {
  res.sendFile('index.html', { root: 'test/public' });
});

app.get('/loged', (req, res) => {
    res.sendFile('loged.html', { root: 'test/public' })
});

app.post('/sessions/listenNewUsers', EasySession.AppendInfoAndReturnId(
    { 
        type: "DB", 
        databaseUrl: DATABASE_URL 
    }
));

app.post('/sessions/verifyId', EasySession.verifyIdAndReturnInfo(
    {
        type: "DB", 
        databaseUrl: DATABASE_URL 
    }
))

app.post('/sessions/logout', EasySession.DeleteInfo(
    {
        type: "DB",
        databaseUrl: DATABASE_URL
    }
));
```

JSON server storage:

```js
import EasySession from "@luccafelipetto/easy-session";
import express from "express";

const app = express();
app.use(express.json());

EasySession.JSON.create('/sessions');

app.listen(3000, () => {
    console.log('Server is running on port 3000');
});

app.get('/', (req, res) => {
  res.sendFile('index.html', { root: 'test/public' });
});

app.get('/loged', (req, res) => {
    res.sendFile('loged.html', { root: 'test/public' })
});

app.post('/sessions/listenNewUsers', EasySession.AppendInfoAndReturnId(
    { 
        type: "JSON", 
        filePath: '/sessions'
    }
));

app.post('/sessions/verifyId', EasySession.verifyIdAndReturnInfo(
    { 
        type: "JSON", 
        filePath: '/sessions'
    }
))

app.post('/sessions/logout', EasySession.DeleteInfo(
    { 
        type: "JSON", 
        filePath: '/sessions'
    }
));

```

---

## Contributing

PV me in discord if you want to help:
**.n4njaezzz**

---

**Stay tuned — EasySession-lib is just getting started!**a