I'm new to jQuery and node.js and this question has been bugging me for a couple of hours, I've searched stackoverflow and googled but couldn't find a solution.
I'm testing this "hello world" example in jQuery and I tried running it with node.js, but it didn't work.
Here is my code for node.js server:
var express = require('express');
var fs = require("fs");
var app = express.createServer(express.logger());
var path = require('path');
var indexText = fs.readFileSync("test.html");
app.use('/jquery', express.static(__dirname + '/jquery'));
app.get('/', function(request, response) {
response.send(indexText.toString());
});
var port = process.env.PORT || 8080;
app.listen(port, function() {
console.log("Listening on " + port);
});
So as you can see, I tried use express.static() to tell the node.js where jQuery lib is located. Here is the html for test.html:
<html>
<head>
<title>jQuery Hello World</title>
<script type="text/javascript" src="/jquery/jquery-1.2.6.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function(){
$("#msgid").html("This is Hello World by JQuery");
});
</script>
This is Hello World by HTML
<div id="msgid">
</div>
</body>
</html>
It should print:
This is Hello World by HTML This is Hello World by JQuery
but it only prints hello from HTML
The question might be stupid but I'm new to this so I require your help. Thank you.
Ok, I found a solution to what I was asking. Here is a git repository with code that helped me:
https://github.com/jmhdez/Nodejs-Sample
and here is the tutorial with the code (it is on Spanish, but let the Google Chrome translate the entire page for you, it is ok)
http://blog.koalite.com/2011/11/tutorial-node-js-express-jquery-i-creando-la-aplicacion/
Thanks everyone once again for your help
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With