0

Not an unsolved problem, but rather a technical question, which I hope is valuable enough to ask.

As a beginner web developer, I attempted to give a variable from a .js file to an .html file, to display a variable from the former on-screen - I desired to do so by the <script src=... parameter. The .js file I wanted to include in the .html is the one that contains the code, which creates the HTTP server (as of yet a simple one) and loads the .html file.

I was told that it is a bad idea, and I should use JSON objects instead. THe problem is therefore solved, but I'm interested: why was it a bad idea to include the script of Express.js within the HTML file?

3
  • Because you'll get errors? Commented Dec 15, 2015 at 10:55
  • 1
    Express needs node. Because it's javascript doesn't mean it needs nothing more than a JS engine. Some javascript needs a browser (and frequently a DOM), some others have other needs. Commented Dec 15, 2015 at 10:56
  • @Andy I didn't, yet I have to admit that displaying variables did not work either. Commented Dec 15, 2015 at 10:57

1 Answer 1

1

Express.js is Node.js web application framework. Lets simply call it backend javascript, which means it's designed to be run not in browser, but as part of Node.js application.

Just FYI:

There is a way to 'run' some Node modules in browser. There is tool called browserify .

Here what they are saying on their web site:

Use many of the tens of thousands of modules on NPM in the browser

I'm afraid that Express.js is not one of those 'many' modules.

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

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.