Introducing Expressive Tea
Tags: javascript, typescript, node, express
Published: 2021-05-26 22:52:46

## Introduction
When I started coding [Expressive Tea](https://expressive-tea.io) almost two years ago, it was just a tool to increase my laziness (as most engineers) avoid setting up a project on [ExpressJS](https://expressjs.com). I was thinking about combining a language that I started to learn (Typescript) and making easier a configuration for **ExpressJS**; by that moment, I did not know about [NestJS](https://nestjs.com), a very mature and fantastic Framework. I did not have a chance to research, just because I got the idea to start working in this new (at that moment) personal library.

In September 2019, that personal library turned into a microframework to help build **server-side** applications in **NodeJS** and use modern **Javascript** powered by **Typescript**. Also, one of the main goals is to make this compatible with all the express middleware and plugins available when I wrote this article; the list continues to expand with ideas and recommendations from friends and users that already started using Expressive Tea.

## What the heck is Expressive Tea?
I define Expressive Tea as a flexible framework that gives freedom to build their own architectures by providing descriptive decorators, a plugin engine, shareable modules, and modern Javascript.

But what does that mean? As I mentioned in the introduction, it is just making developers lazier (for a good reason), helping them forget how to set up ExpressJS, and just working on the business logic. 

Take into consideration that Expressive Tea has not come with anything out of the box; this means no additional plugins or middlewares with exceptions of certain features like **Websockets**, and you might need to provide the necessary plugins to achieve your unique server flavor.

So, telling that, you might still wonder where the flexibility or freedom is in something with nothing more than essential matters. Pleasantly, Expressive Tea has no attachment on any naming convention, any special plugin, or any data source, so this allows you to freely change the application in the way you prefer and introduce two critical entities in the Expressive Tea framework.

### Plugins
A Plugin is an entity to implement features that we need for our applications, such as assigning a connection to MongoDB or changing the server behavior such as adding a view engine, adding authorization middleware, or just adding a body parser.

But more importantly, this can be share between Expressive Tea projects; the method depends on you (like npm package, git submodule, or copy and paste). Still, essentially you will get a path to create many plugins and combine them to flavor on your own Expressive Tea.

### Modules

A Module is pretty similar to Plugin, but instead of change the behavior of the server is used to create a placeholder route to encapsulate controllers and services to respond to a user request through declared endpoints. 

All the endpoints are defined in each ** controller** that have a corresponding method to respond to the client; in simple terms, a Module helps to contain routers in one place, by example, we can have a signing module that contains all the endpoints to sing in or sign up a user into our application.

As same as Plugins, Modules can be share between Expressive Tea applications if they have the following specifications:

- All code must be in the same place; anyone has their own structure and scaffolding methods, ideally set all in the same root directory; the other thing is depends on you ;).
- Should not contain external code, like external classes, services, or constants with certain exceptions like Expressive Tea settings and node packages.

## Demo
We have enough for boring theory; it might be better with a bit of demonstration of how this is working, shall we?..

### Dependencies.

We can start by installing `tea` CLI with the following command:

```shell
npm install -g @expressive-tea/tea
```

> Tea CLI is under development; take patience ;), send comments or open an issue.


### Create a project.


Once `tea` finished to install, now is time to start to create a project with the following command:

```shell
tea brew to-do
```

{% asciinema 415577 %}


Follow all the instructions and change them if you want them. Once create project finished and create our `to-do` project, just go inside with:

```shell
cd to-do
```

and execute the project with:

```shell
tea serve
```

{% asciinema 415579 %}

if you get the following message, congratulations; this is your first Expressive Tea application:

```
[INFO] 14:08:05 ts-node-dev ver. 1.1.6 (using ts-node ver. 9.1.1, typescript ver. 3.9.9)
Fri, 21 May 2021 19:08:06 GMT helmet deprecated helmet.noCache is deprecated and will be removed in helmet@4. You can use the `nocache` module instead. For more, see https://github.com/helmetjs/helmet/issues/215. at server/plugins/express.ts:59:31
Running HTTP Server on [8080]
```

if you open your browser and type `http://localhost:8080/`
you will get the following response:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vz6vxaru0kfl9hfvyxzn.png)

### time to play

Let the fun start :), it is time to move our a little bit our project; the main goal is to create a REST API for a To-Do application, and the first thing to do is remove the static HTML that shows as the index.

It is time to open the `main.ts` file from the application and remove the line `@Static('./public')` (you can use the IDE that you like) as is the following screencast.

{% asciinema 416282 %}

Now the main page is gone is time to implement our first endpoint to this new REST API.

{% asciinema 416285 %}

The application now will return a To-Do list that is on memory, for now, just to not overcomplicate the example.

{% asciinema 416291 %}

For this example need to add one of the elements from Expressive Tea for decorating arguments in the endpoints methods; the `@body()` annotation is part of the package on `@zerooneit/expressive-tea/decorators/annotations` and helps to extract the whole body object as is showing in the screencast above.

> More details you will get in the documentation.

### The Extra
The main goal is to present you a little bit of Expressive Tea, but how to leave without giving you an extra; in this case, I will show you how to modify the Express plugin in the demo to just show a console log.

{% asciinema 416299 %}

### Check our live playground.
I know this is not extensive details in this article, and this is because I just want to inform you more than training you, but if you're going to sneak pick a little more content, there is a series of articles that you can follow, it might be a little old but contains the essential:

{% medium https://medium.com/@diego.resendez/a-simple-rest-api-with-expressive-tea-part-three-6b09f2ad73ad %}

{% medium https://medium.com/@diego.resendez/a-simple-rest-api-with-expressive-tea-part-two-718b1e3ed265 %}

{% medium https://medium.com/@diego.resendez/a-simple-rest-api-with-expressive-tea-part-one-97ef6c08f9c4 %}

Or you can use our sandbox in CodeSandbox, where you will be able to play a little bit or understand more about Expressive Tea.

{% codesandbox expressive-tea-2kmg7 runonclick=1 %}

## Conclusions
As I continue improving this project, I learned and still learn many things technically. Still, the real value is discovering new things to do, challenges, and, more importantly, being active in the Open Source community. Even if this project does not grow much or maybe overextend it, the self-learning of many soft skills comes with this, for example, managing your time, executing a project, and actively checking new features.

Hence, as this work I just take it as a personal challenge it will be good to have help, so if any of you want to help, improving code, adding new issues, do a review, write an article, maybe a YouTube video, or ask for new feature down below you will get the link to the Github Repository of this project.

{% github Expressive-Tea/expresive-tea no-readme %}

Without more to aggregate, let me thank you for reading my article, which is the first on this platform.