Node.js not working on Windows XP machine - node.js

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

Related

Why does NodeJS download the file instead of holding the web

I am not sure about why there is a difference between Mac OS & Windows.
The problem is, on Windows environment, the Chrome/Edge downloads the NodeJS response instead of just loading the webpage. Whenever I visit "localhost:8081" on Chrome/Edge, it happens again and again. I would like to do it as what MAC OS does, anyone can save me?!
Windows Side Response
Windows
On MacOS, it does sticking on the browser window.
Any idea for this issue?
Forgot to mention NodeJs version, MACOS: v10.15.3, WINDOWS: v11.12.0
Hopefully, the version doesn't matter in this case. :'(
MacOS
Thanks!
var http = require('http');
http.createServer(function (request, response){
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('HelloWorld');
}).listen(8081);
console.log('server running at http://127.0.0.1:8081/');

Why does Cloud9 IDE return the error "Script does not exist" when trying to run simple Node.js script?

I am attempting to create a simple Hello World Node.js script using Cloud9 IDE. My code is below and is the atypical 6 lines:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(process.env.PORT);
I don't see any errors and the IDE is certainly not alerting me to any. I've ensured that the file is saved (even going so far as to commit it to my repo). Unfortunately, whenever I try to run the above code I receive the following error:
Error on server
Received following error from server:
"Script does not exist: server.js"
To illustrate the run configuration I've included the below screenshot:
I am pretty sure I am missing something obvious, but whatever it is its alluding me. What do I have misconfigured that could cause my server.js file to not run?
Your configuration is correct, there is however a temporarily problem that causes some of the VM's to not run a file. I've seen it before and it usually goes away after some time. Quick fixes now:
Either wait
Create a new project with the same file, chances are that it'll run
Your filepath doesn't look right. Shouldn't it be server.js and not /server.js? Try creating a new run configuration and set the file path to server.js.

Node.js Web Application running in Windows Azure Emulator

I've been trying Node.js running in Windows Azure Emulator, but unfortunatelly it isn't working. Of course, I started from beginning, Hello World application, following steps in this tutorial.
I followed the steps below with 4 different computers and in all cases the page didn't show anything.
I opened Windows PowerShell environment as Administrator.
I created node directory
I entered the command: PS C:\node> New-AzureService tasklist
I entered the command: PS C:\node\tasklist> Add-AzureNodeWebRole
Here, my application was created with the code above:
var http = require('http');
var port = process.env.port || 1337;
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World\n');
}).listen(port);
And finally, I entered the command: PS C:\node\tasklist\WebRole1> Start-AzureEmulator -launch
Now I was supposed to see my hello world page. The question is, if somebody had success with the given tutorial? And what Am I doing wrong?
I had your exact same error and looking for a long time on the Internet I found this post.
Just to summarize, the problem is that there's a script inside Node package for Azure that's trying to grant permissions for "Network Service" to the web root directory.
However my system language is it-IT, so I don't have a user called "Network Service".
So you need to edit the script. If your application path is C:\node\tasklist then the script is located at
C:\node\tasklist\local_package.csx\roles\WebRole1\approot\bin\setup_web.cmd
Just change this line:
icacls ..\ /grant "Network Service":(OI)(CI)W
with this:
icacls ..\ /grant "NetworkService":(OI)(CI)W
This worked for me!
You can try running the example directly in node using:
node server.js
and pointing a browser to http://localhost:1337. This takes the Windows Azure emulator out of the picture and might indicate if there is something else going on.
I think your case is similar with below article.
http://blogs.msdn.com/b/avkashchauhan/archive/2012/01/31/handling-two-known-issues-with-windows-azure-node-js-sdk-0-5-2.aspx
I hope you can solve the problem by this info.

Node.js console.log() not logging anything

Trying out node.js for the first time. Set up node, set up the example app from the nodejs.org site. Can start the server fine, but console.log() isn't actually logging anything. Tried the Javascript console in Chrome, Firefox, and Safari - nothing appears in the log. Also checked Console on my Mac just for kicks, nothing was there either. What am I missing?
(Here's the example code that works but doesn't log anything.)
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/');
In a node.js server console.log outputs to the terminal window, not to the browser's console window.
How are you running your server? You should see the output directly after you start it.
This can be confusing for anyone using nodejs for the first time. It is actually possible to pipe your node console output to the browser console. Take a look at connect-browser-logger on github
UPDATE: As pointed out by Yan, connect-browser-logger appears to be defunct. I would recommend NodeMonkey as detailed here : Output to Chrome console from Node.js
Using modern --inspect with node the console.log is captured and relayed to the browser.
node --inspect myApp.js
or to capture early logging --inspect-brk can be used to stop the program on the first line of the first module...
node --inspect-brk myApp.js

node.js segmentation fault:11

having a problem getting node.js to run. I'm on OSX Lion, followed the installation instructions for node. I'm on v0.5.9-pre, according to node --version, but when I try to run
node app.js
I get "Segmentation fault: 11".
The app.js file is just the hello world example from the main site:
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/');
Nothing special. Tried looking over the web, but nothing seems to answer this. Any ideas?
I had this after upgrading from Node 0.4 to 0.6. I just needed to delete the node_modules directory from my app and re-install the dependencies with 'npm install' again.
Never mind. Just used homebrew to install node.js/npm and all working fine now. Thanks anyway.

Resources