Node.JS local hosting server manager - node.js

I'm searching for a local hosting server manager for my Node.JS applications that lives on different ports.
All I can find is cloud-based hosting such as: nodejitsu, nodecloud, nodester, heroku and so on.
Is there any hosting environment that can run locally on my personal computer ?
EDITED:
I'm looking for something like Microsoft IIS Server Manager.
That way I can manage my different server apps on different ports/configurations.

What prevents you from downloading node.js from http://nodejs.org/ and installing it on machine of your choice? That's all you need for running node only applications.

Node.js based websites write server software in JavaScript and run it with Node. It isn't used in conjunction with a regular webserver (except when that server operates as a proxy).
If you take a look at, to pick one based on it being at the front of your list, the getting started guide for nodejitsu you will see the code to run an HTTP server in the examples.

Provided you have a public IP & domain-name set up (or use something like localtunnel), it is just a question about starting a Node.js webserver:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(80, '127.0.0.1');
console.log('Server running at http://127.0.0.1:80/');
(Taken from Nodejs.org.)

Related

NodeJS deployment to A2Hosting subdomain?

Long story short, my buddy has an A2 account (hosting his main app on PHP). I wanted to get my hands dirty with Node (particularly the deployment process) and he said I could use his hosting so I've created a subdomain. I've got the subdomain setup and running a hello world script
var http = require('http');
var server = http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
var message = 'Hello world!\n',
version = 'NodeJS ' + process.versions.node + '\n',
response = [message, version].join('\n');
res.end(response);
});
server.listen();
Does anyone have experience deploying node to A2? I'm still pretty new to Node but have enjoyed it so far! Forgive ignorance on the subject, I'm coming from a full stack PHP dev setup.
What I've done so far is work through the Heroku getting started tutorial and have a decent start on the site I'm working on. Locally works great and connecting to my db instance (MySQL). I'm using EJS for templating, etc.
I'm not really familiar yet with creating createServer() functions and such as the Heroku example doesn't seem to go through it but is doing "web: node index.js" from within the proc file.
Is there a way to get the configuration on A2 to run this type of deployment?

How to run a simple 'Hello World' app on shared hosting with Node.js?

I have been running through some basic tutorials with node.js locally on my desktop and all works fine.
I have been trying to run one of the simple 'Hello World!' apps on my 'live' hosting environment. This is not an active website, just some basic web hosting I use for trying things out. My hosting provider offers a node.js addon for a small amount extra per month which I recently signed up for.
I have amended the code in my file (named app.js) so that it references the host and port provided to me by my hosting provider rather than use localhost as it has been previously. The code looks like:
const http = require('http');
const hostname = '195.62.28.216';
const port = xxxx;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
With xxxx being substituted for the port allocated to me.
If I kick this off using my SSH client (PuTTY) by running node app.js, I get the message:
Server running at http://195.62.28.216:xxxx/
However, if I visit that URL, I just get a timeout error:
This site can’t be reached
195.62.28.216 took too long to respond.
When I connect to the host using PuTTY, using the username and password my hosting provider gave to me, it appears to default to a folder named /home/my_username. This is the location of my 'Hello World' app file.
I have contacted my hosting provider's support area, but thought I would post here too whilst awaiting a response in case anybody can point me in the right direction of what I may be doing wrong.
Many Thanks, any assistance greatly appreciated.
Thank all above for the quick responses. I think that the problem is that I was going trying to access the 195.62.28.216:xxxx URL directly from my browser but I think it's set up so that this can only be accessed from my actual web hosting environment.
In other words, I added the below to my .htaccess file on my cloud hosting account:
RewriteEngine On
RewriteRule ^ http://195.62.28.216:xxxx/ [P,L]
And when I now go to my website, I get 'Hello World!' as expected. Now I just need to figure out how to make it so that this only happens when I access a specific folder on my website and not the whole thing... :-)

Display text file using node js from a remote server

Good day! I'm having a hard time fixing this issue. I'm currently using node js webserver (http).
I'm a beginner in using node js so any help would be appreciated.
What I'm hoping to achieve is to display a string 'Hello World!' in the browser while accessing it through the URL. The problem is I'm running the script from a remote server and unfortunately I can't access it through the URL.
The script is running fine but for the browser it returns an error saying:
host didn’t send any data.
ERR_EMPTY_RESPONSE
Here is the script I'm running from the remote server:
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.write('Hello World!');
response.end();
}).listen(2000);
I think my script doesn't have a problem. So I'm guessing it's from the setup of the server, but I don't have any idea in which part it's causing not to display it. I'm currently using a Linux Server.
Thanks in advance!
From what I can see you are listening on port 2000, are you sure that the url you are requesting the data from also contains the port e.g http://localhost:2000/ ?? Browsers by default tries to connect using port 80 on http and 443 for https, if you are listening on a different port than those, you have to define it in the url, by using a ":" after the domain/ip address
Anyway, have a look at the express module for server side rest APIs, will make request handling so much easier:
const express = require('express');
const app = express().listen(80);
app.get("/",function(request,response){
response.send('Hello World');
});
Express allows you to handle the creation of web servers better.
But node or express, do make sure that the URL you have entered consists of the port number that you have asked the server to listen to.
Another possibility is that the port you have asked to display your response is already being used by another server. You can try using a different port number.
You might have gotten the answer, but this is for the folks out there who are new to node at present and have stumbled upon this stackoverflow question! Good day :)

I can't access my node.js server on my AWS EC2 isntance from the outside

I'm trying to run a basic node.js server,
var http = require('http');
http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('hello world!\n');
}).listen(3000, '0.0.0.0', function() {
console.log('Server running on port 3000');
});
However when I run it and go to http://x.x.x.x:3000/ the page doesn't load.
I tried the answer on this question but that didn't work either. And changing the host to 127.0.0.1 or the server ip or emitting it doesn't fix it either.
I've also followed this guide that says to proxy requests with haproxy. But that did not work either.
Is there something in the security tab I have to enable/disable?
Edit: The problem was I was using the wrong IP. The IP changes when the instance is restarted.
Create a rule to open port 3000 in the security group associated with your ec2 instance.
It can be done through the command line tools or through the web console, which is more straightforward. If you didn't specify a security group when creating the instance it will be the "default" security group.
A decent walkthrough for the console
Amazon documentation
Rightscale explanation of different firewall situations

Correct way to forward traffic in nginx to node.js

I want to forward all traffic to a certain URL in nginx to node.js. I'm still new to node.js and I'm wondering if I should be using some kind of CGI service (like PHP) or if I should setup a node.js server (like nginx -> apache) and forward all traffic through nginx to that server like below:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello Node.js\n');
}).listen(8124, "127.0.0.1");
This is only a single page which needs to run a node.js script. What is the best way to do this?
Nginx reverse proxy (aka proxy_pass) doesn't support keep-alive.
But it's possible to establish keep-alive connection for FastCGI using a 3rd party module, Maxim Dounin's Upstream Keepalive module.
By the way, Node.js is yet stable to run without any reverse proxy.

Resources