throubell
v1.0.6
Published
Model that replaces the functions of other modules with those of Throubell, more understandable and easier to handle
Downloads
7
Maintainers
Readme
[email protected]
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 theurl
inside the method, putting the url in single quotes, if everything goes well when making the connection, it will send you a message sayingDataBase is online : url
, on the contrary if something fails this method will throw anerror
.
// 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.
```js
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.
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 seturlDB
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 toproduction
, use this variable to open theport
, it will simply take port3000
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 byconsole
.
- clgSucc:
Invoke
thismethod
and print a message onconsole
if everything went correctly. example:
thr.clgSucc('Sucess message');
- clgWarn: If you want to issue a
warning
use thismethod.
thr.clgWarn('Warning message');
Others Methods
- USE: Basically this
method
helps them to configuremidlewares
.
// 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.
<br>
**example:**
```javascript
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
[email protected]: Nothing
[email protected]: Nothing
[email protected]: Nothing
[email protected]: Nothing
[email protected]: This version
integrates custom console message
types offered by throubell
, also offers functionality
to generate a .gitignore file.
[email protected]: 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.