How to Install AdonisJS Framework: Step-by-Step Guide
AdonisJS is a powerful MVC framework for Node.js, offering an elegant syntax and structure inspired by Laravel. If you’re looking to build scalable server-side applications in a clean and efficient manner, AdonisJS is a great choice. This tutorial will guide you through the process of installing the AdonisJS framework on your machine, from prerequisites to creating your first project.
Prerequisites
- Node.js and npm: AdonisJS requires Node.js (v14 or higher recommended). Check your version by running
node -vandnpm -vin your terminal. - Command Line Interface: Access to terminal or command prompt.
- Basic JavaScript Knowledge: Familiarity with JavaScript and asynchronous programming helps.
Step 1: Install Node.js and npm
If Node.js and npm are not installed, download and install them from the official Node.js website (Official site).
Step 2: Install AdonisJS CLI
AdonisJS provides a CLI tool to create projects and manage commands. Install it globally via npm:
npm i -g @adonisjs/cli
Verify the installation by running:
adonis --version
Step 3: Create a New AdonisJS Project
Use the CLI to initialize a new project. Run:
adonis new project-name --api-only
Replace project-name with your desired project folder name. The --api-only flag creates a lightweight API-focused application without view templates, suitable for REST APIs. Omit it if you want a full web app.
Step 4: Navigate to Your Project Directory
cd project-name
Step 5: Install Project Dependencies
Inside the project folder, run npm to install all required packages:
npm install
Step 6: Run Your AdonisJS Application
Start the development server with:
node ace serve --watch
This command starts a local web server and watches your files for changes, automatically restarting the server as needed.
Open your browser and visit http://localhost:3333 to see your running AdonisJS app.
Troubleshooting Common Issues
- Command not found for
adonis: Ensure that your npm global bin directory is in your system PATH. Reopen your terminal or try installing the CLI again. - Node.js version too low: Check your Node.js version; upgrade to a supported version if below 14.
- Port conflicts: If port 3333 is in use, stop other services or configure AdonisJS to use a different port in
config/app.ts.
Summary Checklist
- Installed Node.js and npm
- Installed AdonisJS CLI globally
- Created a new AdonisJS project
- Installed project dependencies
- Started the development server and accessed the app locally
This tutorial covers your first steps installing AdonisJS so you can start building web apps and APIs. For more Node.js frameworks tutorials, you might find our How to Install Hapi Framework: Step-by-Step Guide helpful for exploring alternatives.
Happy coding with AdonisJS!
