0

I'm new to Nodejs, So help me with this Code

<script>
const os = require('os');
var nam = os.hostname();
document.getElementById('operate').innerHTML=nam;
</script>

<div style="float:left;" id="operate"></div>

Im trying to get nodejs module right inside this html code. Thanks in Advance!

2

1 Answer 1

0

You cannot execute code against the nodejs API inside a web browser. The nodejs api is only available when being executed by the nodejs VM.

Assuming node js is installed locally and available on the PATH.

  1. Create index.js
  2. Input the following

    const os = require('os'); console.log(os.hostname());

  3. Run the js file node index.js

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

2 Comments

You want to say that you cannot use node modules in web apps?
That is not what I said. You can in fact use modules inside a client side web app if you are using something like webpack/browserify to resolve imports/requires. This does not mean you have access to the nodejs api(although some of the api is reimplemented/repackageed as npm modules).

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.