12

Unfortunately JavaScript is the only programming language I have experience with. So naturally my gut instinct is to wonder why you wouldn't write a programming language (in this case Node) in JavaScript?

Why C? What benefits are you getting?

3
  • 5
    Node.js is written in C++. C and C++ are different languages, with different strengths and weaknesses. C is strongest in getting the most direct access and closest control over hardware--the Linux Kernel, for example, is in C. C++ is good at coordinating the connections among hundreds of modules; that suits it well for something like Node. Commented Jan 25, 2017 at 18:58
  • 8
    Node is just Chrome's V8 engine, so your real question is, Why was V8 written in C++? Commented Jan 25, 2017 at 20:03
  • Because you need something to run javascript on, there need to be some base vm, it can't just run on itself. And the VM was written in C++ because its fast and mature, you don't want to wait an eternity for page to load do you ? Commented Jun 25, 2022 at 11:46

3 Answers 3

20

C is a low-level language suited to systems programming--i.e. the construction of operating systems, database engines, and other code that must be highly efficient (in both time and space used to complete a given task). C is "close to the bare metal," compiling everything effectively into machine code and CPU instructions.

You can certainly write compilers and middleware in higher-level languages than C. While there can be a speed-of-development advantage for doing so, they will almost always run slower and consume far more memory. Many languages (Python, PHP, JavaScript, ...) are implemented in C (or C++) as a result.

If you wanted to implement something like Node in another language, you would probably best look to another language that majors on systems programming, such as C++, C#, Rust, D, ...

Sign up to request clarification or add additional context in comments.

4 Comments

Node is written is C++.
The wikipage https://en.wikipedia.org/wiki/Node.js actually references C, C++, JavaScript. But I changed the title of my question!
libuv, which is the absolute core of the high performance asynchronous networking that Node.js is famous for, is written in pure C.
A program is slower if the code which implements it is not optimized or efficient. I believe that the code which implements C++ is provided by a professional team of developers and is much more stable and faster than the C code which can be written by a single developer. An anomalous consumption of memory is often caused by memory leaks which are very common in C code and hard to solve while they can be entirely avoided in C++. So except very specific piece of code, libraries for very specific hardware, is much more convenient to write code in C++. All program lifecycle would benefit from it.
2

Node.js is built on chrome's V8 engine(which allows it to execute javascript), so you should ask that why was v8 written in c++?

This answer on Quora might help you for the 2nd question

Comments

-4

Node js is created using JavaScript language which can be run in the desktop to create application. Node js is also written in C++ because when the web server needs access to internal system functionality such as networking.

C++ has many features that let it directly interact with the OS directly JavaScript does not! So it has to work with C++ to control these computer features.

Referring to client and server side architecture example . (Here Mick is the client) Mick's Mac/Windows needs access to a website which is hosted in the internet somewhere in a server which basically a computer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.