nextjs-hostinger-deploy
v1.0.1
Published
CLI tool for Next.js static export and FTP deployment to Hostinger shared hosting
Maintainers
Readme
nextjs-hostinger-deploy
A CLI tool to export a Next.js project to static files and deploy them to Hostinger shared hosting via FTP.
Short command: Use nhd instead of nextjs-hostinger-deploy (e.g., npx nhd init).
Installation
npm install -g nextjs-hostinger-deployOr for local development:
git clone <this-repo>
cd nextjs-hostinger-deploy
npm install
npm run build
npm linkUsage
Prerequisites
- Your Next.js project must be configured for static export (using pages router).
- Run
npm run buildin your Next.js project before exporting. - Obtain FTP credentials from your Hostinger control panel (see below).
Getting FTP Credentials from Hostinger
- Log in to your Hostinger account at hostinger.com.
- Go to your Hosting dashboard.
- Select your hosting plan/domain.
- In the control panel, navigate to Files > FTP Accounts.
- If no FTP account exists:
- Click Create FTP Account.
- Enter a username (e.g., your domain name or a custom one).
- Set a password (or use the generated one).
- Set the directory to
/public_html(or your desired root). - Click Create.
- Copy the following details:
- FTP Host: Usually
ftp.yourdomain.com(shown in the FTP Accounts list). - FTP Username: The username you created (e.g.,
[email protected]). - FTP Password: The password you set.
- FTP Host: Usually
- Use these in your
.env.localfile or GitHub Secrets asFTP_HOST,FTP_USER,FTP_PASS.
Commands
Initialize Project for Deployment
nextjs-hostinger-deploy init
# or
nhd initThis command:
- Configures
next.config.jsfor static export if not already set. - Creates
.env.examplewith FTP credential placeholders. - Generates
.github/workflows/deploy.ymlfor automated deployment on push to master.
After running init, follow the on-screen instructions to set up credentials and GitHub Secrets.
Export Next.js to static files
nextjs-hostinger-deploy export
# or
nhd exportThis runs npx next export in the current directory.
Deploy to Hostinger via FTP
nextjs-hostinger-deploy deploy -h <ftp-host> -u <username> -p <password> [-d <local-dir>] [-r <remote-dir>]
# or
nhd deploy -h <ftp-host> -u <username> -p <password> [-d <local-dir>] [-r <remote-dir>]-h, --host: FTP server host (e.g., ftp.yourdomain.com)-u, --user: FTP username-p, --password: FTP password-d, --dir: Local directory to upload (default: 'out')-r, --remote: Remote directory on server (default: '/public_html')
Full export and deploy
nextjs-hostinger-deploy full -h <ftp-host> -u <username> -p <password> [-d <local-dir>] [-r <remote-dir>]
# or
nhd full -h <ftp-host> -u <username> -p <password> [-d <local-dir>] [-r <remote-dir>]Combines export and deploy in one command.
Configuration
For security, consider using environment variables or a config file for FTP credentials instead of command-line arguments.
Development
npm run dev # Run with ts-node
npm run build # Compile to JavaScript
npm start # Run compiled versionPublishing to npm
To make this package available on npm for others to install:
Testing Locally First
Before publishing, test the package locally to ensure it works:
- In this project directory, link it globally:
npm link - Create a test Next.js project in another directory:
npx create-next-app test-project cd test-project - Link the local package:
npm link nextjs-hostinger-deploy - Test the commands:
nhd init nhd export # After building: npm run build - If issues, fix and rebuild (
npm run build), then unlink and relink.
Publishing to npm
- Ensure you have an npm account: Sign up at npmjs.com if you don't have one.
- Log in to npm via CLI:
npm login - Update
package.jsonif needed:- Ensure
nameis unique (checked:nextjs-hostinger-deployis available). - Set
versionto a new version (e.g., increment from current, like1.0.1). - Add a
repositoryfield:"repository": "https://github.com/yourusername/nextjs-hostinger-deploy"
- Ensure
- Build the project:
npm run build - Test publish (dry run):
npm publish --dry-run- This simulates publishing without actually uploading.
- Publish for real:
npm publish- For a beta release:
npm version prerelease(e.g.,1.0.1-beta.0), thennpm publish --tag beta. - Users can install beta with
npm install nextjs-hostinger-deploy@beta.
- For a beta release:
After publishing, users can install with npm install -g nextjs-hostinger-deploy or npm install --save-dev nextjs-hostinger-deploy.
