I have installed node.js from here http://nodejs.org/ . in my windows8 machine. copied the example server code in my server.js file
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/');
then opened the node.js prompt and written node c:/node/server.js but nothing happens. I am a php developer just trying hands on it, any guidelines will really be helpful.
Node. js provides capabilities to create your own web server which will handle HTTP requests asynchronously. You can use IIS or Apache to run Node. js web application but it is recommended to use Node.
You don't need to go in node.js prompt, you just need to use standard command promt and write
node c:/node/server.js
this also works:
node c:\node\server.js
and then in your browser:
http://localhost:1337
Nodejs is a scripting language (like Python or Ruby, and unlike PHP or C++). To run your code, you need to enter a command in the terminal / shell / command prompt. Look for an application shortcut in your operating system by one of those names.
The command to run in the terminal will be
node server.js
But you will first need to browse in the terminal to the same folder as the file server.js
. The syntax for using the terminal varies by operating system, look for its documentation.
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