# How to Debug Node.js Segmentation Faults

DevFeed: [How to Debug Node.js Segmentation Faults](<https://devfeed.tech/articles/how-to-debug-node-js-segmentation-faults-19065.md>)

Original publisher: [Read original article](<https://httptoolkit.com/blog/how-to-debug-node-segfaults/>)

Author: HTTP Toolkit; Tim Perry

Published: 2020-08-12T11:20:00Z

Content type: tutorial

Language: en

Sources: [HTTP Toolkit](<https://devfeed.tech/sources/http-toolkit.md>)

Topics: [Node.js](<https://devfeed.tech/topics/node-js.md>), [debug](<https://devfeed.tech/topics/debug.md>), [JavaScript](<https://devfeed.tech/topics/javascript.md>), [Processes](<https://devfeed.tech/topics/processes.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [cors](<https://devfeed.tech/tags/cors.md>), [crash](<https://devfeed.tech/tags/crash.md>), [debug](<https://devfeed.tech/tags/debug.md>), [exception](<https://devfeed.tech/tags/exception.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [js](<https://devfeed.tech/tags/js.md>), [linux](<https://devfeed.tech/tags/linux.md>), [memory](<https://devfeed.tech/tags/memory.md>), [memory-management](<https://devfeed.tech/tags/memory-management.md>), [node](<https://devfeed.tech/tags/node.md>), [node-js](<https://devfeed.tech/tags/node-js.md>), [process](<https://devfeed.tech/tags/process.md>)

## AI overview

A practical guide to understanding and debugging Node.js segmentation faults. It explains that segfaults occur when a process violates operating-system memory-access rules, often involving invalid memory addresses, pointers, buffer or stack overflows, and native code such as native addons.

## Source excerpt

Oh no, your JavaScript code isn't just throwing an exception or crashing: it's segfaulting. What does that mean, and how can you fix it? You'll know this happens because node will hard crash, exiting silently without any kind of real stack trace, perhaps printing just segmentation fault (core dumped). (If you do get a normal JavaScript stack trace on the other hand, then you're dealing with a normal JS error, not a segfault. Lucky you! You might be more interested in the guide on How to Debug Anything) What is a Segmentation Fault? A segmentation fault occurs when a program attempts to access a memory location that it is not allowed to access, or attempts to access a memory location in a way that is not allowed (for example, attempting to write to a read-only location, or to overwrite part of the operating system). - wikipedia.org/wiki/Segmentation_fault In practice, a segfault occurs when your program breaks some fundamental rule set by the operating system. In that case, the operating system sends your process a signal (SIGSEGV on Mac & Linux, STATUS_ACCESS_VIOLATION on Windows), and typically the process shuts down immediately. The rules that you can break to cause this include things like reading or writing to an invalid memory address (e.g. native code somewhere trying to use a null pointer as a memory address), causing a stack or buffer overflow, or reading or writing from memory that's not yours (maybe it was yours but it's now been released, maybe it's unused, or maybe it's owned by another process or the operating system). All of these cases involve low-level concerns, like pointers & memory management. You shouldn't normally have to worry about this when writing JavaScript! The language runtime normally manages your memory, doesn't expose the kinds of APIs that could cause these issues, and enforces its own rules on the APIs that are available, to guarantee that your code behaves correctly. That all ensures that the underlying operating system's rules are