Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am a complete node.js newbie and struggling with the basics.I have a html file and I would like to call external javascript file in the html page using node.js in local host environment.

share|improve this question
    
What Node.js have to do with html? There are Node.js modules to emulate web browser behavior, but are you sure it's really what you want? –  Leonid Beschastny Nov 12 '13 at 10:41
1  
Could you tell us what you're trying to achieve? Also, please read the XY Problem to better define your question. –  Paul Mougel Nov 12 '13 at 11:48
add comment

2 Answers

You just add the script tag into the html:

<script type="text/javascript" href="/path/to/src.js"></script>
share|improve this answer
    
This will execute the script client-side, not "using node.js in local host environment". –  Paul Mougel Nov 12 '13 at 10:44
    
Oh, I see that - I'd read "would like to call external javascript file in the html page". I think it could be read either way, but I did think the question was a little simplistic with my interpretation! –  Adam Hopkinson Nov 12 '13 at 11:41
add comment

I think I have understood your real interest.

<script src="script.js"></script>

If you are trying to get a script tag (like that one above) working on your html, you should write a "router" inside your Node.js http.createServer callback. When the browser find the script tag, it will send a specific request to the server and then you can send the javascript code back on the response.

I have written a way to do it on a similar question here: How to include javascript on client side of node.js?.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.