Guide
How to run a Node.js app on shared hosting
You can run a small Node.js app on shared hosting by creating a Node.js application in the control panel, setting the app root and start file, installing dependencies and adding environment variables. It suits small APIs, simple servers and apps that listen on a port handled by the host. Heavy or long-running background workers need a different kind of server.
Setting up
Setting up a Node.js app, step by step
Prepare the app
Make sure it has a package.json file and a start file such as app.js, and that it runs on your own computer first.
Upload it
Upload the project to a folder in your hosting account over SSH or SFTP, outside the public web folder if you can.
Create the application
In the control panel, open the Node.js selector, create an application, choose the version, the app root and the start file, and set the app’s address.
Install dependencies
Use the selector’s install button, or run the install command over SSH, so the packages in package.json are installed.
Add environment variables and start
Enter secrets and settings as environment variables in the selector, then start the app and visit its address.
Worked example
A worked example: a small enquiry API
A designer’s static site has an enquiry form. Instead of paying for a form service, she writes a tiny Node.js app with one route that receives the form data and emails it using her domain mailbox. It is about forty lines of code.
She uploads the project, creates a Node.js application in the selector, sets the start file and adds the mailbox password as an environment variable. After installing the dependencies and starting the app, she points the form at its address, and sends a test message.
The email arrives in seconds. The app uses a few megabytes of memory, well within the limits. She keeps the password out of the code and out of Git, and she restarts the app from the selector after each update. The whole thing costs nothing beyond her hosting plan.
Troubleshooting
When the app will not start
If the app does not start, read the error. Most problems are simple: a missing dependency because the install step was skipped, a wrong start file name, a Node.js version that does not match the one the code expects, or a missing environment variable that the code needs.
Check the log files. The selector or your account usually provides an error log for the app, and it normally names the file and line where it failed. Fix that, restart and try again.
Another common cause is the app trying to listen on a fixed port. On shared hosting the selector decides how requests reach your app, so follow its instructions for the port or socket, and do not hard-code one. If you are stuck, our live chat can help, and our guide to fixing a 500 internal server error covers the common server-side faults.
Keeping it healthy
Logs, restarts and updates
Once the app is running, keep an eye on it. Check the logs after each deploy, and look at memory use over the first few days. If the app crashes or restarts often, read the log for the cause, which is usually an unhandled error or a leak.
Update dependencies now and then. Outdated packages can contain security holes, so run an audit command, update what you can and test before redeploying. Keep the Node.js version supported, because older versions stop receiving fixes.
Always keep your code in Git, so you can redeploy, roll back and see what changed. A small app that is looked after for ten minutes a month will run for years.
Security
Keeping a small Node.js app safe
Treat anything a visitor sends as untrusted. Validate input, limit its size and never build database queries or commands by joining strings from users. Use well-known libraries for sessions, passwords and security headers instead of writing your own.
Keep secrets out of the code and out of Git, use HTTPS everywhere, and return generic errors to visitors while logging the details privately. If the app handles personal data, add it to your privacy notice.
Host your project on UK servers
SSH, Node.js and Python selectors, free SSL and live chat open 24/7 on every plan, from 84p a month (£10.03 billed yearly).
FAQ
Common questions
Can I run Node.js on shared hosting?
Yes, for small apps, using a Node.js selector. Our plans include one.
What is a Node.js selector?
A control panel tool that runs your Node.js app, sets its version and start file, and connects it to your domain.
Which apps suit shared hosting?
Small APIs, webhook receivers, form handlers and simple server-rendered sites. Heavy workers do not.
How do I set secrets?
Use environment variables in the selector. Never put them in code or Git.
Why will my app not start?
Check missing dependencies, the start file name, the Node.js version and environment variables, and read the log.
Do I need SSH?
It helps for uploads and installs. SSH is included on every plan.
Can I run Express or Next.js?
Express apps usually suit it. Next.js with server features depends on resources, so static exports are the safest route.
How do I update a running app?
Upload the changed files, reinstall dependencies if they changed, then restart the app from the selector and check the log.
Is my Node.js app secure on shared hosting?
The platform adds isolation and a firewall, but your code must still validate input and keep secrets safe.
Which Node.js version should I choose?
Choose the version your code was written and tested with, ideally a currently supported release, and keep it updated so you keep receiving security fixes.
Keep reading
Related pages
Deploy your project on a plain yearly price
SSH, Node.js and Python selectors and free SSL on every plan, with a 15-day money-back guarantee.