Prepare and upload a Node.js project
Requirements
- a domain or subdomain pointing to the correct server,
- a project with
package.jsonand preferably a lock file, - DirectAdmin and, depending on the method, Terminal or SSH access,
- a Node.js version supported by both the project and server.
Application location
Use a dedicated account directory, for example:
/home/USERNAME/domains/DOMAIN/app/The source can remain outside public_html. Public static assets belong in the framework's public directory or a dedicated document root.
- Upload sources,
package.jsonand one lock file. - Create
node_moduleson the server; never copy it from Windows or another platform. - Do not upload development caches, local logs or
.gitunless required. - A
.envfile can contain secrets. Keep it out of the public web directory with secure permissions.
Install and build
cd ~/domains/DOMAIN/app
node -v
npm -v
npm ci
npm run buildUse npm ci with a current package-lock.json. Otherwise use npm install and commit the resulting lock file. The build must succeed before the application is created or restarted.
Run commands in the selected Node.js runtime. With CloudLinux Selector, use the environment activation command displayed by the application.
Before production
- Set production mode and all required environment variables.
- Do not run a built-in development server in production.
- Never put secrets directly in
package.json, a URL or a public repository. - Back up the application, configuration and database.