Use d8 functions in Nodejs

mrzrm :

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.

jfriend00 :

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?

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=31960&siteId=1