I installed node.js new version and I checked in command prompt by using node-v and npm-v I want to know how create and run that file.
Asked
Active
Viewed 3,293 times
-4
-
See http://stackoverflow.com/questions/2353818/how-do-i-get-started-with-node-js – matth Oct 30 '13 at 19:15
-
You will find countless guides on this if you use google – Nilzone- Oct 30 '13 at 19:18
2 Answers
1
Create the file hello.js in the root directory of your project, and fill it with the following code:
var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(8888);
First, execute your script with Node.js in the command prompt:
node hello.js
open your browser and point it at http://localhost:8888/
. You will see a message "Hello World" .

Md. Al-Amin
- 1,423
- 1
- 13
- 26
0
You can start the Node.js process like this:
% node example.js
Server running at http://127.0.0.1:1337/

Eddie Martinez
- 13,582
- 13
- 81
- 106
-
C:\Neetesh\Node.js\node_modules\npm\test\hello.js:1 (function (exports, require, module, __filename, __dirname) { consol.log('Hell ^ ReferenceError: consol is not defined at Object.
(C:\Neetesh\Node.js\node_modules\npm\test\hello.js:1:6 3) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:901:3 – user2938731 Oct 31 '13 at 17:29 -
C:\Neetesh\Node.js\node_modules\npm\test\hello.js:1 (function (exports, require, module, __filename, __dirname) { consol.log('Hell ReferenceError: consol is not defined at Object.
(C:\Neetesh\Node.js\node_modules\npm\test\hello.js:1:6 3) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at node.js:901:3 i am getting this error while running the file – user2938731 Oct 31 '13 at 17:31 -
I would suggest finding and fixing the typo-ed `console.log`. That should immediately fix that error message. – Claudia Apr 14 '14 at 21:13