Node.js not working on windows (file error) - node.js

I had installed node.js and when I try to exceute simple Hello world it opens that file, instead of showing me the hello world and also it opens the same file every time, whether I try to execute the different .js files. I'm new to node.js, kindly help...thanks in advance!

Download the Windows executable here: http://nodejs.org/#download
Copy the file to C:\
Create C:\hello.js
Paste in the following content:
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/');
Save the file
Start -> Run... -> cmd
c:
C:>node hello.js
Server running at http://127.0.0.1:1337/

Related

node server.js is not working due to syntax error?

I am trying to learn node.js and like many others, the first step is like How to run server written in js with Node.js
However, my problem is syntax problem? (as follows)
server.js
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/');
That's a different program called Node. You may want to uninstall it, then install actual Node from here:https://nodejs.org/en/download/

Node.js not working on Windows XP machine

I am just getting started with node.js and I have followed multiple tutorials to get it working on my Windows XP machine.
Downloaded the msi and installed with no issues, opened a command prompt and typed node -v and nothing displays. I created a folder and made a JS file with console.log('hello'); in it, changed to that directory and typed node hello.js and nothing shows.
I then added this code to the hello.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/');
and ran the file from the command line again, it paused briefly and then again displayed nothing.
Been through 10 different tutorials on 10 different sites and can't find a thing to answer this question, even all the information here was no help at this point.
I have also checked the path and it is fine and rebooted the machine just in case.
Seriously stuck!
You need to set your path to node (Environment Variable). Check the following address:
http://www.hacksparrow.com/install-node-js-and-npm-on-windows.html
This is necessary for running node from any folder in the system.
Or you can add node as an enviroment variable in Windows XP's settings:
https://support.microsoft.com/en-us/kb/310519

Cannot run node.js example. module.js:340 throw err cannot find module

When I type in node example.js to my command prompt it gives me an error message.
This is the code I'm using.
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, 'localhost');
console.log('Server running at http://localhost:1337/');
I got that directly from the node.js website and it worked last night. It won't work today. Some help would be appreciated please.
Node.js looks for the file you pass it in the current directory.
If the file only exists in a different directory, it will not be able to find it.
You need to either save the file to the correct directory, or use cd to switch to the directory containing the file.

node set up and install

from my understanding I need to create a file called server.js and then paste this code in it
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');
Where do I put this file?
I know where the node_modules folder is but I am not sure where to sit this server.js file.
You can put the server file anywhere that you want. Once you've done that, open Command Prompt or Terminal and enter this command:
cd C:\the\full\path\to\the\file\server.js
but, of course, enter the correct path to the server.js. After that, you should enter the command:
node server.js
And the server will start!

Node.js - Basic example not working

I have been trying to figure out why i cant get even the most basic Node.js application to run, all day. I have installed Node on my Media Temple (dv) server in the root using PuTTy NOT on my local machine.
When i do 'node --version' it shows me the version, which tells me that Node is correctly installed. However when i attempt to do the basic 'HTTP' example it doesnt work when i go to http://mysite.com:1337, instead the connection just times out.
The JS is below:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, "mysite.com");
console.log('Server running at http://mysite.com:1337/');
Node.js really interests me so would be good if i can understand why it isnt working.
Thanks in advance.
How about:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337);
console.log('Server running at http://mysite.com:1337/');
Without specifying the host?
Change listen(1337, "mysite.com") to listen(1337, "0.0.0.0"), that should work.

Resources