How to publish a NestJS project to your hosting account

Programming, error messages and sample code > Node.js
Nest (NestJS) is a framework for building efficient, scalable Node.js server-side applications.
 
Please follow the deployment instructions:
 
1. install the Nest CLI and create a new project
 
npm i -g @nestjs/cli
nest new project-name
2. change the highlighted content in the main.ts file and ensure that you do NOT define the variable "PORT" in the .env file
 
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

const port = process.env.PORT || 3000;

async function bootstrap() {
    const app = await NestFactory.create(AppModule);
    await app.listen(port);
}
bootstrap();
3. run the application in the development environment
 
cd project-name
npm run start
it will start the development server at http://localhost:3000
 
4. design your application, test it with the development server, prepare to deploy the application
 
npm run build
it will generate the production files in dist folder
 
5. upload all the files in dist folder and upload the entire node_modules folder to your website via FTP client
 
 
7. replace the contents of the root web.config with the following:
 
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="iisnode" path="main.js" verb="*" modules="iisnode" />
        </handlers>
        <rewrite>
            <rules>
                <rule name="mysite">
                    <match url="/*" />
                    <action type="Rewrite" url="main.js" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>