I was wondering can node.js 开发者_C百科run with Apache server? My understanding with this language was that js files gets compiled with Google V8 engine but how do we do this?
How do we use this for building web apps?
One way to create http servers in node is the very popular framework express: https://github.com/visionmedia/express
Example Code (from there):
var app = express.createServer();
app.get('/', function(req, res){
res.send('Hello World');
});
app.listen(3000);
I was wondering can it run with Apache server?
Of course. You can run node.js on whatever port you like (subject to the usual limitations) leaving Apache free to have port 80 (or whatever port you like). Apache can easily proxy requests to node if you write your script to communicate over http.
My understanding with this language was that js files gets compiled with Google V8 engine but how do we do this?
From the node.js homepage:
node example.js
How do we use this for building web apps?
There is an example of writing a webserver using node.js on the node.js homepage.
TeaJS runs V8 on Apache, and its pretty easy to use. http://qteajs.org Similar syntax to Node, but with the synchronous programming and Apache. You just include mod_js in httpd.conf, and write JavaScript in .sjs files (instead of PHP or insert your favorite language here)
http://nodejs.org no seriously just read the front page.
They have a pretty clear example.
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
You will need to install linux or osx to run nodejs for now.
精彩评论