1.0.6 • Published 5 years ago

throubell v1.0.6

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

Throubell@1.0.5

Version Status Build Status checks Status Release Status License Status

Throubell is a module that is in its initial stage, it has some basic functionalities such as: get, put, post, etc. throubell will facilitate some tasks for you to connect to a database and create a js file that creates configurations for you, these are some of its simple functionalities, remember that it is only in its initial stage, the goal is to shorten some methods , throubell is made with express, the objective is to shorten methods and make the code easier, I will update it weekly, for more information on how to use the documentation, I hope you find it useful.

Install:

You should first install it with the following command

npm i throubell

You will have to request it in your javascript file and set the class with which it will be handled

const throubell = require('throubell');
const thr = new throubell();

How to use:

To use your methods use thr at the beginning of each method.

thr.method();

Open Port

To open a server on the port heard by your pc or on the 3000, use the following syntax:

thr.onPORT(process.env.PORT || 3000); // throubell issues a message if the port was successfully opened, the same will happen with the error

body-parser

throubell incorporates the body-parser module, in order to make the correct adjustments use the following syntax.

// extended: false
thr.extendedBody(false);
// jsonBody
thr.jsonBody();

Static Files

To use static files the following method must be used:

thr.staticFiles(// path of files);

//Example

thr.staticFiles('public');

HTTP methods

The http methods are important when developing a web application, that's why throubell offers you some of the most important htpp methods, they are not 100% tested, in fact, it is very likely that an error will occur when developing, leave comments about errors.

GET

  • The GET method is used as follows
thr.get('/', (req, res) => {
    res.json({
        ok: true,
        name: 'name'
    });

    // your code
})

POST

  • The POST method is used as follows
thr.post('/', (req, res) => {
    let body = req.body;
    // your code
})

PUT

  • The PUT method is used as follows
thr.put('/', (req, res) => {
    // your code
})

DELETE

  • The DELETE method is used as follows
thr.delete('/', (req, res) => {
    // your code
})

Note: get methods are very important when making requests, it is also useful when rendering a file. check doc


Mongoose

In throubell we have incorporated some shortened methods, mongoose now it will be better to use some methods, simpler and improved, remember that it is in version 1.0.0, so there are not many features for this, in the future we will be adding much more things.

Methods:

  • directConnectToDB: This method allows you to connect to a mongo database just by putting the url inside the method, putting the url in single quotes, if everything goes well when making the connection, it will send you a message saying DataBase is online : url, on the contrary if something fails this method will throw an error. example:
thr.directConnectToDB('mongodb://localhost:27017/test');

on the other hand if you store the DB in a variable, you simply have to put the variable inside the method.

// declare variable
let DB = 'mongodb://localhost:27017/test';

// enter the variable in the method
thr.directConnectToDB(DB);

Note: later we will see how to create a config file automatically with throubell, config file where all the port configurations will be, until connecting to a Mongo Atlas DB.


WebSockets in server (BUILDING)

Well, throubell has decided to implement websockets, throubell websockets is written under socket.io 2.0, sockets are only available for the server side, we are working to update and update it for the frontend, this version of socket offered by throubell is not It has been 100% tested so it is very likely that some type of error will happen, in fact the possibilities are 95%, we are working to test it well and update it, I have been very busy so it has not been possible to dedicate myself to 100% module, here a little tutorial.

Methods

  • on: The on method is used to listen to some event such as the connection or disconnect.
thr.on('connection', function(client){
    //client.on
    //client.emit

    // others events
});

How to create a config file automatically

  • configHelper: This method will allow you to create a js file with some settings that throubell do for you, these settings are so that your app can be launched into production, you simply have to request the file from your main js file and make use of its variables. Note: You should create a folder named helper or config, you should configure the path inside the method, the path will have to put it in single quotes, in the path you will write in which folder you want the config to be stored ('src/helper/'), it is important that you put a sidebar at the end of the folder where you want it to be stored, if you don't put the sidebar at At the end the configHelper.js file will be stored in the previous folder, in this case in src. example:
thr.configHelper('src/helper/');

In this case a file called configHelper.js will be created inside the helper folder.

How to use configHelper.js file

To use the configHelper.js file you must require it in your main js file.

require('//path of your configHelper.js file');
  • process.env.URLDB: go to configHelper.js and set urlDB variable, just change the database path.
let urlDB;

if (process.env.NODE_ENV === 'dev') {
    urlDB = 'mongodb://localhost:27017/test'; // local dataBase
} else {
    urlDB = 'mongodb+srv://username:<password>@cluster0-mbqdw.mongodb.net/database'; 
    // your url mongoDB Atlas
}

process.env.URLDB = urlDB;

Once you've configured that, you can go to your main js file and use the process.env.URLDB variable

thr.directConnectToDB(process.env.URLDB);
  • process.env.PORT: To configure the port and be able to launch the app to production, use this variable to open the port, it will simply take port 3000 and if it does not exist it will take the one given.
thr.onPORT(process.env.PORT);

Console Messages

Throubell offers you the functionality of being able to print messages by console with its personalization, here we will leave you the clg that you can use.

  • clgErr: This method will print an error message by console. example:
thr.clgErr('Error message');
  • clgSucc: Invoke this method and print a message on console if everything went correctly. example:
thr.clgSucc('Sucess message');
  • clgWarn: If you want to issue a warning use this method.
thr.clgWarn('Warning message');

Others Methods

  • USE: Basically this method helps them to configure midlewares. example: let's take the body-parser configuration for this.
thr.extendedBody(false);
// you can also write like this
const bodyParser = require('body-parser');
thr.use(bodyParser.urlencoded({extended: false}));

// other example

thr.jsonBody();
// you can also write like this
thr.use(bodyParser.json());
  • gitIgn: Use this method if you want to generate a .gitignore file. example:
thr.gitIgn(boolean, [data], 'message');
// example
thr.gitIgn(true, ['node modules'], 'git ignore create succefully');

boolean: In the boolean it must have a value of true since if it has false the file will not be generated.

data: In the data is the value that we enter in the .gitignore file and what will not upload when uploading our file to github.

message: This will be the message that the console prints if it was possible to generate the file with the data.


Releases

Throubell@v1.0.1: Nothing Throubell@v1.0.2: Nothing Throubell@v1.0.3: Nothing Throubell@v1.0.4: Nothing Throubell@v1.0.5: This version integrates custom console message types offered by throubell, also offers functionality to generate a .gitignore file. Throubell@v1.0.6: This version integrates how to call Static Files and how use socket with throubell.`


More Information

This package was made by luis-dev-npm, The objective of this package is simply to make the code smaller in different proportions, for more information visit the doc.

throubell.org

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago