Prerequisites

Before starting the deployment process, ensure the following prerequisites are met:

  1. Node.js installed (preferably the LTS version).
  2. A production database that can be accessed from your production environment.
  3. Environment variables set for production configuration.

Step 1: Build the Application

The first step in deploying the app is to build it. Execute the following command to compile the TypeScript code:

npm run build

This command will generate the necessary JavaScript files in the build directory. Ensure that your tsconfig.json is correctly set to include all necessary files.

Step 2: Set Environment Variables

In the production environment, you must set the appropriate environment variables to configure the app. This can usually be done with a .env file or directly in your server configuration. Example environment variables include:

NODE_ENV=production
DATABASE_URL=mongodb://user:password@host:port/database
PORT=3000
JWT_SECRET=your_jwt_secret

Ensure the values are securely stored and not hard-coded in the codebase.

Step 3: Start the Application

Once the build is complete and environment variables are set, you can start the application. Use the following command to run the application in production mode:

npm start

Make sure your package.json has a start script defined, typically invoking the compiled output:

"scripts": {
  "start": "node build/index.js"
}

Step 4: Configure Reverse Proxy (Optional)

For production deployments, it is common to use a reverse proxy server such as NGINX to manage incoming requests. A sample configuration might look like this:

server {
    listen 80;

    server_name yourdomain.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

Save this configuration in your NGINX configuration directory (e.g., /etc/nginx/sites-available/yourapp) and create a symlink to the sites-enabled directory.

sudo ln -s /etc/nginx/sites-available/yourapp /etc/nginx/sites-enabled/

Restart NGINX to apply the changes:

sudo systemctl restart nginx

Step 5: Set Up Process Management

For managing the application process in production, it’s advisable to use a process manager like PM2. Install PM2 globally using npm:

npm install -g pm2

Then, use PM2 to start your application:

pm2 start build/index.js --name "apps-client" --env production

You can also configure PM2 to automatically restart your app on server reboots:

pm2 startup
pm2 save

Step 6: Monitoring and Logging

Ensure that proper monitoring and logging are set up for your production environment. PM2 provides built-in logging:

pm2 logs

You can also integrate other monitoring tools like New Relic or Sentry according to your needs.

Conclusion

Follow these steps to successfully deploy helixml/apps-client in a production environment. Ensure continual monitoring and testing to maintain a smooth operation. Regularly update dependencies and handle security measures diligently.

Source: Project codebase and established best practices for Node.js applications.