http://www.basicspace.org:5000/#/
Here is my url, I want to run the app just on the http://www.basicspace.org without the port number. I have seen lots of tutorials but none got into my head so asking it here for better solutions.
If it is just a single EC2 Instance which is running NodeJS then. If it listens behind and ELB, then PORT source and destination to be configured in ELB.
var util = require('util');
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, { 'Content-Type': 'text/plain' });
response.write('Hello World');
response.end();
}).listen(80);
Related
I have set up a simple HTTP server with NodeJS that is working in Local Mode, but when I'm executing it on a Debian server, I can't access it, this is my simple code:
var http = require('http');
var fs = require('fs');
console.log("ok1");
var server = http.createServer(function (req, res) {
fs.readFile('index.html', 'utf-8', function (error, content) {
res.writeHead(200, {
"Content-Type": "text/html"
});
res.end(content);
});
});
var io = require('socket.io').listen(server);
io.sockets.on('connection', function (socket) {
console.log('Un client est connecté !');
});
server.listen(8080);
And I get this error:
error
Thank you very much !
The server seems fine. It probably isn't the problem. Try pinging the server from your machine and pinging your machine from the server. If it only goes one way then the issue must be firewall. If it doesn't go both ways make sure they are actually on the same network.
I have a small node program.
console.log("Program Started");
var http = require('http');
//Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
console.log("Processing Request for URL" + request.url);
response.writeHead(200, {"Content-Type": "text/html"});
response.end("Hello World \n");
});
// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);
console.log("Program Ended");
If I run this program on my MacBook and access the following URL, I see my Hello World message.
http://localhost:8000/
However, I'd like to have this URL responding to HTTPS connections as well.
https://localhost:8000/
How can I do this with NodeJS?
Can the native http library do this for me? Or will I need Express?
Yes you can simply do It via https module :
1 you will have to create certificats , you can follow this auto here for macOS
https://stackoverflow.com/a/42298344/8395557
I am using http module in my project but most of my 'post' requests are blocked by postman.
I read it is a ssl issue,after some research i found another module named https.
Here is my current code.
var http = require('http');
var server = http.createServer(app);
Hei, make sure that the interceptor in Postman is off (it should be in the top, left to the "Sign in" button)
And related to https, as stated in Node.js v5.10.1 Documentation
HTTPS is the HTTP protocol over TLS/SSL. In Node.js this is implemented as a separate module.
I used it once to make requests from my server to other servers over https (port 443).
btw, your code shouldn't work, try this
const http = require('http');
http.createServer( (request, response) => {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8124);
console.log('Server running at http://127.0.0.1:8124/');
and use http://127.0.0.1:8124 in Postman
..hoped it helped
const http = require('http');
http.createServer( function(request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(3000);
console.log('Server running at http://localhost:3000/');
The difference between HTTP and HTTPS is if you need to communicate with the servers over SSL, encrypting the communication using a certificate, you should use HTTPS, otherwise you should use HTTP, for example:
With HTTPS you can do something like that:
var https = require('https');
var options = {
key : fs.readFileSync(path.resolve(__dirname, '..', 'ssl', 'prd', 'cert.key')).toString(),
cert : fs.readFileSync(path.resolve(__dirname, '..', 'ssl', 'prd', 'cert.crt')).toString(),
};
var server = https.createServer(options, app);
server = server.listen(443, function() {
console.log("Listening " + server.address().port);
});
I'm running an apache and ubuntu server on aws.
Both the below files run but when I access the server only the top one returns Helloworld. Why is that?
var http = require('http');
var port = 3000;
var server = http.createServer(function(req, res) {
console.log(req.headers);
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end('<h1>Hello World</h1>');
});
server.listen(port);
The bottom file runs but doesn't when I hit the server I get an error. I tried replacing hostname with the ip of the server, I also tried making the host name 127.0.0.1 that didn't work either. The error I get is
"This site can't be reached, <ip> refused to connect, ERR_CONNECTION_REFUSED"
is the ip of the server.
var http = require('http');
var hostname = 'localhost';
var port = 3000;
var server = http.createServer(function(req, res) {
console.log(req.headers);
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end('<h1>Hello World</h1>');
});
server.listen(port, hostname);
Cheers
If you're listening on localhost, you have to make the request from the same machine/server and not from the outside.
I'm following the node.js tutorial in here,
http://net.tutsplus.com/tutorials/javascript-ajax/learning-serverside-javascript-with-node-js/
this is the code,
var sys = require("sys"),
http = require("http");
http.createServer(function(request, response) {
response.sendHeader(200, {"Content-Type": "text/html"});
response.write("Hello World!");
response.close();
}).listen(8080);
sys.puts("Server running at http://localhost:8080/");
in here, it says run like this url,
server's ip:8080/
but if i do this,
it just shows, cannot connect to this url.
i opened 8080 port in the server.
===========================
I'm assuming something is screwed up with codeigniter url helper...
The tutorial may be using an incorrect or deprecated method. Replace
response.sendHeader(200, {"Content-Type": "text/html"});
with
response.writeHead(200, {"Content-Type": "text/html"});
and
response.close();
with
response.end();
I Agree with the answer of Third .... make those changes and if it is local use this URL
http://127.0.0.1:8080/
But
If you are running your server not on localmachine but on something like webserver(AWS), You have to let the security of AWS firewall to allow the port to be public on the internet and also remember to use the AWS instance URL
http://AWSinstanceURL:portno/
Use this one
//Lets require/import the HTTP module
var http = require('http');
//Lets define a port we want to listen to
const PORT=8080;
//We need a function which handles requests and send response
function handleRequest(request, response){
response.end('It Works!! Path Hit: ' + request.url);
}
//Create a server
var server = http.createServer(handleRequest);
//Lets start our server
server.listen(PORT, function(){
//Callback triggered when server is successfully listening. Hurray!
console.log("Server listening on: http://localhost:%s", PORT);
});
Now open http://localhost:8080 and u will get your result.