Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
264 views
in Technique[技术] by (71.8m points)

node.js - How do I import an existing NodeJS project to NestJS

I have a large and complex NodeJS project, with ejs files and assets scrambled inside - it's a bit of a mess. It was built for several years with a lot of server side functionality (connecting to other systems, analyzing data, managing users, etc.) and client side functionality (map with leaflet, having diagrams, configurable elements, menus, etc.). What I'm trying to say is - it's a code/asset bulk, but it's working well. The thing is - it can't go on like this forever, because as we add features the complexity rises, bugs are harder to find and tackle and performance lacks.

I want to move to NestJS. What I want to do is to create a NestJS skeleton that runs the legacy app as it is, and then start chopping off different behaviors to modules.

I've tried to copy the entire legacy app's folder to NestJS's src folder, and then I created a new legacy module. That module's code looks like that:

import { Module, OnModuleInit } from '@nestjs/common';
import { LegacyController } from './legacy.controller';
import massApp from '../legacy-server/serverApp';

@Module({
  controllers: [LegacyController]
})
export class LegacyModule implements OnModuleInit {
  onModuleInit(): any {
    massApp.run();
  }
}

But I get an error -

Error: Cannot find module '../../server-mass/serverApp'

because NestJS tries to compile the app and on the way removes many resources, assets, and makes a mess of it.

All I want is a way to leave the app as it is, start it as usual, but have NestJS initiate that process and behave as a proxy to incoming requests (so that I can hijack these requests for the behaviors I start implement myself).

Does that make sense? Any ideas how it can be done?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...