Node.js Web Application running in Windows Azure Emulator - node.js

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.

Related

hosting a discord bot on cPanel

I have a problem that when I want to turn on my discord bot on my server that uses cPanel, I can't get it to work from the node.js control panel without putting the shell command node index.js into the package.json file and using the run script function of the panel. the problem with this is that the only way to stop the bot is to use the eval command on discord, since I don't have proper terminal access.
In addition to what #Verdigris answered above, you can use Glitch too, just make sure to use Runtime Bot so you can keep your Discord bot up 24/7.
Important: code to add on your main node.js file:
const http = require('http');
const express = require('express');
const app = express();
app.get("/", (request, response) => {
console.log(Date.now() + "Ping Received");
response.sendStatus(200);
});
app.listen(process.env.PORT);
setInterval(() => {
http.get(`http://${process.env.PROJECT_DOMAIN}.glitch.me/`);
}, 280000);
And as always, cheers.
On cPanel you will never have full terminal access, so what I suggest you do is just keep the NPM start script, then create a command for the bot that issues the process.exit() function. This function essentially stops the entire NodeJS Process. If you are looking for an alternative that provides full terminal access I recommend buying a cheap VPS from a decent provider such as OVH.
If your cPanel account has a in-browser terminal, you can enter the virtual environment by pasting the command that appears at the top of the Node.js control panel into there. It is something like:
source ~/nodevenv/<name_of_node_application>/10/bin/activate && cd ~/<path_to_node_application>
You will then have access to node and npm, and can then start your discord bot like you normally would like:
node <name_of_node_application> &
and kill it by running kill -TERM with node's pid, from ps -ax.
However, you can't reliably use the Node.js panel to stop a daemon script, as described here:
cpanel node.js Can't acquire lock for app: app

Need help getting simple node.js express to run

I'm trying a simple sample of node express that I copied from online. The script is below which I think is pretty standard.
var http = require('http');
http.createServer(function(request, response)){
response.writeHead(200);
response.write("hello");
response.end();
}).listen(8080);
console.log('listening on port 8080...');
I used the bash on ubuntu on windows command as follows:
npm init
node SampleServer.js (the name of my file)
When I do this, I expect some response from the command line. But when I enter the "node SamplerServer.js" command, nothing happens. When I direct the browser to port 8080, I get an error message as well.
I'm using nodeclipse and the installing that on my machine was pretty complicated. Prior to any of the steps above, I created an express project in eclipse ide. It seems to perform a lot of pre steps but in the end, I think I'm getting some of the error messages below. I'm mentioning this because I'm thinking perhaps I installed one of the modules wrong.
enter image description here
Start with simple stuff...
Use express-generator to create simple app by the following command
1-> npm install -g express-generator with root or Admin access
2-> Run express demoapp.
3-> Navigate to demoapp
4-> Do npm install
5-> Run from command with npm start: it run by default on http://localhost:3000
Hit that URL from Browser

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

http server listening in old port

First i installed the node js with webmatrix and ran a sample node js app. the app was assigned a random port. http://localhost:62369/. After that i installed the express module. As said in their doc. i wrote,
var app = express();
app.get('/',function (req, res) {
res.send('hello world!!');
})
app.listen(3000);
Then i restarted the server. The launched browser was still pointing to http://localhost:62369/ instead of port 3000. Moreover http://localhost:3000/ was not working.
I suggest you to run this code so you can see if you have any problem on saving the code with your IDE:
var app = express(),
port = 4555;
app.get('/',function (req, res) {
res.send('hello world!!');
})
console.log("Server is running on " + port);
app.listen(port);
After that, you need to change the port variable only. It's helpful if you comment what you see after running this code on the console.
make sure that you've saved your code in your file (open it with another editor, maybe something's wrong with your editor), close the command line window and open it again. try to run server. I'm sure the problem is not because of node or express. Try to check everything again.
And also run your server with command line:
cd path/folder
node myFile
I don't know what are you using to run server, but if it's something with UI (in comments you mentioned a click) it can cache your code or something like that. So it's safer to run with commend line.

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.

Resources