What causes a folder to disappear after rerunning in nest.js?

When working on my project using nest.js in MacOS Sonoma, I encountered a problem where the image folder src/products/images gets deleted after every project rerun (npm start).

The images are saved like this:

for (const image of images) {
  const fileName: string = uuid.v4();
  const fileExtension: string = image.originalname.split(".").pop();
  const filePath: string = `${productImagesDir}/${
    fileName + "." + fileExtension
  }`;

  console.log(image);

  await fs.promises.copyFile(image.path, filePath);

  let productImage = this.productImageRepository.create({
    product: product,
    url: `http://localhost:5500/api/product/images/${fileName}.${fileExtension}`,
  });
  await this.productImageRepository.save(productImage);
  successFullyUploadedImages.push(productImage);
}

However, after running npm start, the "dist/product/" directory does not contain an "images" folder. I tried adding this to the Product module:

MulterModule.register({
  storage: diskStorage({
    destination: "./src/product/images",
    filename: (req, file, cb) => {
      const uniqueSuffix: string = v4();
      const extension = file.mimetype.split("/")[1];
      console.log(uniqueSuffix);
      console.log(extension);
      cb(null, `${uniqueSuffix}.${extension}`);
    },
  }),
});

Unfortunately, this solution did not solve the issue.

Answer №1

Graphic files such as .png or .jpg are considered assets. By default, NestCLI does not pay attention to assets. If you want NestCLI to include assets in the /dist folder, you will need to modify the configuration file nest-cli.json.

For more information on how to configure nest-cli.json, I suggest taking a look at this helpful answer:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Looking to create universal React component wrappers?

I am working with a set of functional components that share a common set of properties, for example: const A = ({ x, y, z }) = {...} const B = ({ x, y, z }) = {...} For these components, I have predefined configurations: const styles { A: { ty ...

Utilizing Angular routing in HTML5 mode within a Node.js environment

While I've come across other solutions to this problem, they all seem to have drawbacks. One option leads to a redirect, which could be disastrous for my front-end application that relies on Mixpanel. A double-load of Mixpanel results in a Maximum Ca ...

Create a TypeScript declaration file for a JavaScript dependency that contains an exported function

I am currently utilizing a dependency called is-class in my TypeScript project. Unfortunately, this particular dependency does not come with a @types definition. As a workaround, I have been using a custom .d.ts file with declare module 'is-class&apos ...

Problem with character encoding in Node.js

I am encountering an issue while retrieving data from a request, as the formatting or encoding is not matching my requirements. Attempted to address this by setting the encoding with req.setEncoding('utf8') The expected string should appear as: ...

Is NoSQL supported by the MySQL Community Edition?

I have decided to dive into learning and developing a Node.js application with SQL. I am aware that the MySQL Enterprise Edition offers support for NoSQL, but I'm curious if the community edition also supports NoSQL or if I need to invest in the enter ...

How many installation packages does Appium require?

Currently, I am in the process of installing the most recent version (1.6.3) of appium using npm. There seems to be an overwhelming number of various packages being downloaded by npm during the installation, and I am uncertain if all of these packages are ...

Instance property value driven class property type guard

Is it possible to create a class example that can determine the config type based on the value of animalType instance: enum Animal { BIRD = 'bird', DOG = 'dog', } type Base = { id: number } // Object example type Smth = Base & ...

Error in Typescript: Function expects two different types as parameters, but one of the types does not have the specified property

There's a function in my code that accepts two types as parameters. handleDragging(e: CustomEvent<SelectionHandleDragEventType | GridHandleDragEventType>) { e.stopPropagation(); const newValue = this.computeValuesFromPosition(e.detail.x ...

Tips for setting up npm dependencies in a subfolder

Within the main directory, I have a package.json file that contains this command: "install": "cd packages/my-package && yarn". Every time I execute yarn run install, my intention is for it to enter into the specified package, set up the node modul ...

Nuxt.js pages are displaying a 404 error, indicating that the content cannot

I've developed a nodejs project using adonuxt and have SSL enabled on my website. The issue I'm facing is related to using nginx as a reverse proxy to handle requests to localhost:port on my server. There are two main problems that I'm enc ...

What is the functionality of the toArray method?

var retrieveDocs = function (db, callback) { var collection = db.collection('tours'); collection.find({ "tourPackage": "Snowboard Cali" }).toArray(function (err, data) { console.log(data); callback; }) } Is there a p ...

Recursive types in TypeScript allow for the definition of types that

Is there a way to implement the function below without utilizing any? Playground type MyType = { name: string, age: number, score: { prime: number, }, prize: { first: { discount: number } } } export const trim = ( myObj: ...

What is preventing this string from converting or retaining its numerical value?

My brain must be tired because this code is not making any sense to me right now.. // take user input, if it's a string, // set result to 0 and return. function evalInput(_input) { // set default result to 0, which is a number var result = ...

The TypeScript error message states, "The property 'breadcrumb' is not found within the type 'Data'."

My Breadcrumb Component is functioning properly when compiled to JavaScript and displaying the desired output. However, my IDE is showing an error message that I am struggling to fix. The error states: [ts] Property 'breadcrumb' does not exist o ...

Is it advisable to utilize a NodeJS global for accessing configuration properties within my application?

Allow me to pose a straightforward question: Within NodeJS, there exists the option to define globals using GLOBAL.myConfigObject = {...} I am curious about the opinions of the developer community on whether this method is considered best practice. If n ...

PhpStorm is unable to resolve the @ionic/angular module

I have encountered a peculiar issue with my Ionic v4 project. While the project runs smoothly, PhpStorm seems unable to locate my references to @ionic. https://i.stack.imgur.com/umFnj.png Interestingly, upon inspecting the code, I realized that it is act ...

Determining the data type of a property within an interface using TypeScript

Is there a way to extract the type from an interface based on its property name in order to use it in a Record? I am struggling with the syntax needed to retrieve the type by property name. My goal is to make this process more future-proof so that if the i ...

Using the power of node.js to iterate through a loop of queries and execute

While I am running a for loop, within the loop itself I am executing a PostgreSQL query and storing the result in an array. However, I am unable to determine the order of execution. Here is my code: var array =[]; for(var i = 0 ; i< latitude.le ...

Difficulty rendering images and CSS during preloading in a Node.js environment

I'm aware of the necessity to use a middleware, but I need guidance on how to implement it correctly. Here is the snippet of code I currently have: const prerender = require('prerender'); var server = prerender({ chromeFlags: ['--no-s ...

Should I share a single DB connection throughout the entire app or establish a new connection to the DB for each request?

I am currently working on developing an API using Nodejs and Restify. My database of choice is MongoDB, with the use of Mongoose. One question that has been on my mind is whether it would be better to share a database connection throughout the entire appl ...