1

Today I decided to compete in an online programming contest using JavaScript for the first time but It got me in trouble! My local version of Nodejs was v10.16.1 but the online judge used V8 JavaScript engine.

Until today I thought Nodejs uses V8 as JavaScript engine; however unfortunately I can't use readline and print built-in functions of d8 in Nodejs today.

So Does Nodejs support V8 by default?

  • If no, how can I install d8 alongside Nodejs and how can I use it?
  • If yes, how can I enable it?

Any response would be appreciated...

Edit: As far as I realized, that online judge isn't embedding V8; It just uses d8 as it's environment which is a shell (interface) for V8 and readline and print are the built-in functions of the d8 (not V8).

Edit: This question is related to using JavaScript in online contests. Also this one is helpful for how to use d8.

13
  • Node.js uses V8, but print and readline are not built-in functions in V8. Commented Mar 6, 2020 at 16:06
  • You need to add const readline = require('readline'); at the top of your script, to be able to use it. Maybe the contest platform does that for you Commented Mar 6, 2020 at 16:07
  • 2
    d8 !== V8 ... Commented Mar 6, 2020 at 16:10
  • 1
    @mrzrm V8 - JS engine, d8 - JS shell for V8, Node.js v8 - version of Node.js Commented Mar 6, 2020 at 16:17
  • 1
    D8 is basically a sample program by the V8 developers to show how to use V8 as a library. Google Chrome for example does not include D8 code even though it uses V8 so Google Chrome does not have print and readline. Node.js did the same thing, they wrote a competitor/alternative to D8 and not include any D8 code in Node instead choosing to create the function console.log and the readline and fs modules Commented Mar 6, 2020 at 17:20

1 Answer 1

2

V8 is a Javascript engine. It does not have a user interface of it's own so it can't run Javascript all by itself. It's for developers. A developer links V8 into their program in order to be able to run Javascript from their program.

The Chrome browser uses V8.

Nodejs uses V8.

D8 (a programming shell) uses V8.

So, if you want to run Javascript with V8, you must run one of these programs that has V8 built into it.

So Does Nodejs support V8 by default?

Yes, V8 is built into Nodejs.

If no, how can I install V8 alongside Nodejs and how can I use it? (I prefer pre-built and binary version)

It's already built in.

If yes, how can I enable it?

It is enabled by default in the Nodejs environment.

Until today I thought Nodejs uses V8 as JavaScript engine; however unfortunately I can't use readline and print built-in functions of V8 in Nodejs today.

You would have to show your specific code and problem using readline in node.js. readline is built-into node.js and is not part of V8. The documentation for something like readline shows examples quite clearly of how to use it. You must first load the readline module and then use methods from that module.

Today I decided to compete in an online programming contest using JavaScript for the first time but It got me in trouble! My local version of Nodejs was v10.16.1 but the online judge used V8 JavaScript engine.

It's unlikely the online contest was using V8 directly. They were likely using a programming environment that itself has V8 linked in. You would need to be more specific about exactly what programming environment the programming contest is using. Is it using a specific version of Nodejs? Or a programming shell like D8? Or a browser?

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

6 Comments

"A developer links V8 into their program in order to be able to run Javascript from their program." How do they do it?
@mrzrm - You start here. Then, you can read the doc on embedding V8 into your program. V8 has a C++ programming interface so that's what you'll be using to interface with it directly and to embed it in your program.
You would have to show your specific code and problem using readline in node.js. readline is built-into node.js and is not part of V8. I saw here d8 doesn't need to require it. So I thought it's built-in V8
Is it using a specific version of Nodejs? Or a programming shell like D8? Or a browser? They uses D8 as their environment.
@mrzrm - Everything I've seen says you build D8 yourself. FYI, your question itself does not mention D8 at all. I know you mentioned that in your comments, but if someone was just reading your question, they would be confused since you don't run V8 directly by itself.
|

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.