Node.js memory limit, 노드 메모리 제한하기

To set the memory size when running a Node.js application with npm, you can adjust the memory limit by setting the --max-old-space-size flag, which increases the V8 (JavaScript engine) heap size. This can be done in a few ways:

1. Directly in the Command Line:

You can run your npm script with the --max-old-space-size flag:

node --max-old-space-size=4096 your-script.js

This sets the memory limit to 4GB (4096 MB). You can adjust the value depending on the desired memory limit.

2. In Your package.json Scripts:

You can modify your package.json file to include this flag within your npm scripts.

{
  "scripts": {
    "start": "node --max-old-space-size=4096 your-script.js"
  }
}

Then, you can run your script using npm:

npm run start

3. Using Environment Variables:

You can also set an environment variable to increase the memory limit.

On Linux or macOS:

NODE_OPTIONS="--max-old-space-size=4096" npm run start

On Windows (Command Prompt):

set NODE_OPTIONS=--max-old-space-size=4096 && npm run start

This sets the memory limit to 4GB.

Let me know if you need help with something else!

댓글

이 블로그의 인기 게시물

PYTHONPATH, Python 모듈 환경설정

You can use Sublime Text from the command line by utilizing the subl command

git 명령어

[gRPC] server of Java and client of Typescript

[Ubuntu] Apache2.4.x 설치

Create topic on Kafka with partition count, 카프카 토픽 생성하기

리눅스의 부팅과정 (프로세스, 서비스 관리)

Auto-populate a calendar in an MUI (Material-UI) TextField component

The pierce selector in Puppeteer