Articles on: Websites & APIs

How to host an Express.js application (Node.js)

1. Prerequisites


Before deploying your Express application, make sure you have:

  • Square Cloud Account: Create your account via the Registration Page (Email or GitHub).
  • Active Plan: A paid plan is required for hosting. Check the pricing here.



2. Technical Web Server Configuration


For Square Cloud to route external traffic to your application, your Express server needs to be listening on the correct interfaces and ports.


In your main code file (e.g., index.js or app.js), configure app.listen with the following parameters:


  • Host: 0.0.0.0 (This allows the server to accept connections from outside the container).
  • Port: 80 (The default port used by Square Cloud's load balancer).


Code Example

import express from 'express';
const app = express();

const PORT = 80;
const HOST = '0.0.0.0';

app.get('/', (req, res) => {
res.send('Express server running on Square Cloud!');
});

app.listen(PORT, HOST, () => {
console.log(`Server running at http://${HOST}:${PORT}`);
});



3. Deploying


When deploying your application through the Square Cloud Dashboard, pay attention to these steps:


  1. Compression: Create a .zip file with your source code and package.json (do not include the node_modules folder).
  2. Upload: In the Dashboard, select the file to upload.
  3. Network Configuration: In the upload menu, it is essential to check the "Publish to Web" option.
  4. Subdomain: Define the name of your free subdomain (e.g., my-api). The final address will be my-api.squareweb.app.



4. Custom Domains (Standard+ Plan)


If you have a Standard plan or higher, you are not limited to the .squareweb.app subdomain.


  • You can configure your own domain (e.g., www.yourcompany.com) through the Network tab in the application settings, as detailed in our DNS guides.
  • Square Cloud automatically manages the SSL certificate (HTTPS) for both the free subdomain and your custom domain.



5. Performance and Security Tips


  • Environment Variables: Use Square Cloud's ENVs to manage API keys and database secrets, avoiding exposing sensitive data in your code.
  • Access Logs: Use the dashboard's Logs tab to monitor requests and identify potential errors (status 404, 500) in real time.

Updated on: 06/13/2026

Was this article helpful?

Share your feedback

Cancel

Thank you!