An open API service indexing awesome lists of open source software.

https://github.com/mensenvau/uzdev


https://github.com/mensenvau/uzdev

expressjs framework library nodejs

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

          

# uzdev

## Installation

You can install the package via npm:

```bash
npm install uzdev
```

## Configuration

Add the following variables to your environment file (.env.development, .env.production, or .env):

```bash
# MySQL module

MYSQL_USERNAME=
MYSQL_HOST=
MYSQL_DATABASE=
MYSQL_PASSWORD=
MYSQL_WAIT=true # defaul
MYSQL_CONNECTION_LIMIT=10 # defaul
MYSQL_QUEUE_LIMIT=0 # defaul
MYSQL_MULTIPLE_STATEMENTS=true # defaul
MYSQL_CONNECT_TIMEOUT=60000 # defaul
MYSQL_DATE_STR=true # defaul

# Function module

JWT_KEY=
JWT_EXPIRES_IN=10d # defaul

# Sender module

EMAIL_LOGIN=
EMAIL_PASSWORD=
FROM_EMAIL=
SMS_ESKIZ_TOKEN=,
SMS_ESKIZ_EMIAL=,
SMS_ESKIZ_FROM=

# for logs to save on telegram bot
BOT_TOKEN=
MAIN_CHAT=
APP_NAME=

# File uploader
UPLOAD_SIZE=5120 #5mb
UPLOAD_ROOT=public/uploads/
UPLOAD_ALLOWED_MIME_TYPES=application/pdf,image/jpeg,image/png

```

## Example

### MySQL Module

```javascript
const { execute } = require("uzdev/mysql");

(async () => {
try {
const result = await execute("select * from fact_users", [], 1);
console.log(result);
} catch (error) {
console.error(error);
}
})();
```

### Function Module

```javascript
const { enCode, deCode, randomCode } = require("uzdev/function");

(async () => {
try {
const encrypted = await enCode({ hello: "salom" });
console.log(encrypted);
console.log(deCode(encrypted));
} catch (error) {
console.error(error);
}
})();

// example random code create
randomCode(5); // 37453;
```

### Sender Module

You will need to buy an SMS package from "eskiz.uz" and you will need to create a specific text template "eskiz.uz".

```javascript
const { emailSender, smsSender, botSender } = require("uzdev/sender");

(async () => {
emailSender("balkibumen@gmail.com", "Test email", " Hello bro ", (email, status, message) => {
if (status == 1) return console.log("SUCCESS", email, message);
console.log("ERROR", email, message);
});

smsSender("995441550", "Webdoc.io platformasi uchun tasdiqlash kodi: 12345", (phone, status, message) => {
if (status == 1) return console.log("SUCCESS", phone, message);
console.log("ERROR", phone, message);
});

botSender("this is error!");
})();
```

### DevOps

Can create a sequence of commands as desired
For example, to do git push and pull, you don't need to learn webhook or other additional tools.

```json
{
"push": [
{
"name": "add",
"command": "git add ."
},
{
"name": "commit",
"command": "git commit -m 'Update from $(whoami) on $(date +\"%Y-%m-%d %T\")'"
},
{
"name": "push",
"command": "git push"
}
],
"pull": [
{
"name": "pull",
"command": "git pull"
},
{
"name": "pm2 restart",
"command": "pm2 restart all"
}
]
}
```

```bash
# command example:
uzdev run push
uzdev run pull
```

### Joi

```javascript
const Joi = require("joi");
const { body, params, query } = require("uzdev/joi");

const YOUR_SCHEMA = Joi.object({
name: Joi.string().min(5).max(200).required(),
// more
});

app.put("/companies", body(YOUR_SCHEMA), YOUR_NEXT_ROUTER);
app.put("/companies", params(YOUR_SCHEMA), YOUR_NEXT_ROUTER);
app.put("/companies", query(YOUR_SCHEMA), YOUR_NEXT_ROUTER);
```

## File uploader

```javascript
// const filter = /* this is for multer fileFilter */
const { fileUploader } = require("uzdev/uploader");

app.post("/user/upload", fileUploader("pdf"), YOUR_NEXT_ROUTER);
// or
app.post("/user/upload", fileUploader("pdf", filter), YOUR_NEXT_ROUTER);
```

## License

This README covers the installation, configuration, and usage of your npm package `uzdev`, including examples for each module. Adjust the placeholders with your actual credentials and customize it further if needed.