The `hapi new` command within the Hapi CLI is used to scaffold a new Hapi.js project. It sets up a basic directory structure with essential files and configurations, allowing you to quickly get started with developing a Hapi application.
hapi new <project-name> [options]* `<project-name>`: The name of the new project directory that will be created. This directory will contain all the project files.
When you run `hapi new`, the Hapi CLI performs the following actions:
1. **Creates a New Directory:** A new directory named `<project-name>` is created in the current working directory.
2. **Scaffolds Project Structure:** Essential files and directories are generated inside the new project directory, typically including:
* `package.json`: Manages project metadata and dependencies.
* `index.js` or `server.js`: The main application entry point.
* `lib/` or `src/`: Directory for application logic (e.g., routes, plugins).
* `.gitignore`: Specifies files and directories to be ignored by Git.
3. **Installs Dependencies:** The command typically runs `npm install` or `yarn install` (depending on your default package manager or specified option) to install all the necessary Hapi.js framework packages and other dependencies defined in `package.json`.
#### 1. Creating a Basic Hapi Project
To create a new Hapi.js project named `my-first-hapi-app` in the current directory, simply run:
hapi new my-first-hapi-app**Explanation:**
This command will:
* Create a new directory named `my-first-hapi-app`.
* Populate it with a basic Hapi project structure.
* Install all required Node.js packages, making the project ready to run.
After the command completes, you can navigate into your new project directory and start the server:
cd my-first-hapi-app
npm start # or node index.js, depending on the generated package.json scriptsWhile specific options can vary between versions of the Hapi CLI, some common patterns for project scaffolding tools include:
* `--git`: Initialize a Git repository (usually default).
* `--npm` / `--yarn`: Specify the package manager to use for installing dependencies. If not specified, it often tries to detect or defaults to `npm`.
* `--template <template-name>`: To scaffold from a specific project template if the CLI supports multiple predefined templates.
Always refer to the official Hapi CLI documentation or run `hapi new --help` for the most accurate and up-to-date list of options and their usage.