node.jsnestjsweb-config

Nest js deploying on MonsterASP


I'm currently working on deploying a NestJS application on MonsterASP and would appreciate any guidance or shared experiences from those who have undertaken a similar task.

What I've Done So Far:

Application Setup: Developed a NestJS application and built it using npm run build, resulting in a dist/ directory containing the compiled JavaScript files.​

Startup Script: Created a server.js file at the root of the project with the following content:​

const { AppModule } = require('./dist/app.module');
  const { NestFactory } = require('@nestjs/core');

  async function bootstrap() {
    const app = await NestFactory.create(AppModule);
    await app.listen(process.env.PORT || 3000);
  }

  bootstrap();

Configuration File: Added a web.config file in the /wwwroot directory with the following configuration:​

<configuration>
    <system.webServer>
      <handlers>
        <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
      </handlers>
      <httpPlatform processPath="node" arguments=".\server.js" startupTimeLimit="20" stdoutLogEnabled="true" stdoutLogFile=".\logs\node">
        <environmentVariables>
          <environmentVariable name="PORT" value="%HTTP_PLATFORM_PORT%" />
          <environmentVariable name="NODE_ENV" value="production" />
        </environmentVariables>
      </httpPlatform>
    </system.webServer>
  </configuration>

File Upload: Uploaded the dist/ directory, server.js, package.json, and web.config to the /wwwroot directory on MonsterASP.​

Issue Encountered:

Upon accessing the application, I receive the following error:

HTTP Error 502.5 - Process Failure​

This suggests that the application process failed to start or didn't listen on the configured port.​

Request for Assistance:

Has anyone successfully deployed a NestJS application on MonsterASP?​

Are there specific configurations or steps I might be missing?​

Is there a recommended approach for installing Node.js dependencies (node_modules) on MonsterASP?​

Any insights, suggestions, or shared experiences would be immensely helpful. Thank you in advance for your support!


Solution

  • Just points web.config file to ./dist/main.js and then upload the node_modules directory and your .env file , and your nest js app is working 👌