Skip to main content

1. Creating a New Herbs Project

Introduction to Herbs

Herbs helps you build backend applications faster and adds more value for your domain and business logic. You can find out more about it here What's Herbs?

If you don't want to see a step-by-step tutorial but an application running with Herbs, you can visit our Getting Started section.

To help with setup process, Herbs has a herbs-cli which starts up a new project scaffolding.

In this tutorial, we are going to walk through all Herbs features by building a User application.

What to Expect

  • You will learn Herbs architectural concepts
  • 2 entities
  • 3 use cases
  • Database access and Repositories
  • GraphQL Types, Mutations and Queries
  • Documentation with Herbs Shelf

Requirements

  • You need to have Node.js installed into your machine with LTS version

Project Setup

You will learn how to use Herbs with hebs-cli or manually. But we strongly recommend that you use our herbs-cli

With herbs-cli

  1. Install herbs-cli globally:
npm i -g @herbsjs/herbs-cli 
  1. Create a new project using it:
herbs new
  1. Answer the questions and create the project:

Folder Structure

The folder structure generated by the CLI is as follows:

.
├── node_modules
├── package-lock.json
├── package.json
└── src
├── config
│ ├── api.js
│ ├── index.js
│ └── mongo.js
├── domain
│ ├── entities
│ │ ├── index.js
│ │ └── user.js
│ ├── errors
│ │ ├── index.js
│ │ ├── notFound.js
│ │ └── notValid.js
│ └── usecases
│ ├── index.js
│ └── user
│ ├── createUser.js
│ ├── deleteUser.js
│ ├── findOneUser.js
│ └── updateUser.js
├── index.js
└── infra
├── api
│ ├── graphql
│ │ ├── defaultResolver.js
│ │ ├── index.js
│ │ ├── inputs.js
│ │ ├── mutations.js
│ │ ├── queries.js
│ │ └── types.js
│ ├── rest
│ │ └── index.js
│ └── server.js
└── data
├── database
│ └── index.js
└── repositories
├── baseRepository.js
├── index.js
└── userRepository.js

Manually

You can also set up the file by your own. To help you on that, we have an extension for VS Code with code snippets and templates.