CLI Companion

  • Hugging Face CLI
    • login
    • whoami
    • repo create
    • upload
    • download
    • lfs-enable-largefiles
    • scan-cache
    • delete-cache
  • Hapi CLI
    • new
    • start
    • build
    • test
    • plugin create
    • route add
  • Cloudflared
    • tunnel
    • tunnel run
    • tunnel list
    • tunnel delete
    • access
    • access tcp
    • update

    The `new` command in the Hapi CLI is used to scaffold a new Hapi.js project. It generates a basic project structure with essential files and configurations, allowing you to quickly start developing a Hapi application.

    Syntax

    bash
    hapi new <project-name> [options]

    - `<project-name>`: (Required) The name of your new Hapi project. This will also be the name of the directory created for the project.

    Options

    The Hapi CLI `new` command typically supports a limited set of options, as its primary purpose is simple scaffolding. Common options might include:

    * `--template` or `-t`: Specifies a particular template to use for scaffolding. While Hapi CLI historically had a default template, some versions or community forks might support custom templates. (Note: Modern Hapi scaffolding often relies on `npx create-hapi-app` or manual setup for greater flexibility).

    Usage Examples

    #### 1. Creating a basic Hapi project

    To create a new Hapi project named `my-hapi-app` with the default template, navigate to your desired parent directory in the terminal and run:

    bash
    hapi new my-hapi-app

    This command will:

    1. Create a new directory named `my-hapi-app`.

    2. Inside `my-hapi-app`, it will generate a basic Hapi project structure, which typically includes:

    * `package.json` (with `hapi` as a dependency)

    * `index.js` or `server.js` (a basic Hapi server setup)

    * Possibly `lib/` for routes and plugins, and `test/` for tests.

    3. It might also automatically install the necessary npm dependencies (like `hapi`) using `npm install` or `yarn install` within the new directory.

    After creation, you would typically navigate into the new directory and start the server:

    bash
    cd my-hapi-app
    npm install   # If dependencies weren't installed automatically
    npm start     # Or 'node index.js' depending on your package.json scripts

    #### 2. Specifying a template (if supported)

    If a version of the Hapi CLI or a related tool supports different templates, you might use an option like `--template`.

    bash
    hapi new my-api-project --template api-starter

    (Note: This is illustrative. The original Hapi CLI primarily offered one default scaffold. For more advanced Hapi project creation, tools like `npx create-hapi-app` or manually setting up `package.json` are more common today, providing more flexibility in structure and dependencies.)

    Explanation

    The `hapi new` command is a convenience tool designed to accelerate the initial setup of a Hapi.js application. Instead of manually creating directories, `package.json` files, and a basic server structure, the CLI automates these repetitive tasks. This allows developers to jump directly into writing application logic rather than spending time on boilerplate. It ensures a consistent starting point for new Hapi projects within an organization or for personal projects, following common best practices and directory layouts provided by the tool's maintainers.