I'm struggling to get a simple node application to run on IIS using iisnode. Here is the application:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('Hello, world! [helloworld sample; iisnode version is ' +
process.env.IISNODE_VERSION + ', node version is ' +
process.version + ']');
}).listen(process.env.PORT);
Here is the error that I'm getting:
Application has thrown an uncaught exception and is terminated:
Error: listen EACCES
at errnoException (net.js:901:11)
at Server._listen2 (net.js:1020:19)
at listen (net.js:1061:10)
at Server.listen (net.js:1127:5)
at Object.<anonymous> (C:\Program Files\iisnode\www\helloworld\hello.js:6:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
Because this is on my dev box I've given the app_pool superuser privileges but that hasn't helped.
Related
I ran this code:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World!');
}).listen(8080);
I am getting the following error:
Error: listen EADDRINUSE: address already in use :::8080
at Server.setupListenHandle [as _listen2] (net.js:1290:14)
at listenInCluster (net.js:1338:12)
at Server.listen (net.js:1425:7)
at Object.<anonymous> (/home/dell/foo.js:6:4)
at Module._compile (internal/modules/cjs/loader.js:707:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:718:10)
at Module.load (internal/modules/cjs/loader.js:605:32)
at tryModuleLoad (internal/modules/cjs/loader.js:544:12)
at Function.Module._load (internal/modules/cjs/loader.js:536:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:760:12)
Emitted 'error' event at:
at emitErrorNT (net.js:1317:8)
at internalTickCallback (internal/process/next_tick.js:72:19)
at process._tickCallback (internal/process/next_tick.js:47:5)
at Function.Module.runMain (internal/modules/cjs/loader.js:763:11)
at startup (internal/bootstrap/node.js:303:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:872:3)
So, here is some code I invoked in order to find out the process running at the port in the terminal:
❯ fuser 8080/tcp
~
But it turns out there is no process running on that port.
How do I fix this?
(I am new to node.js. I will appreciate any help in the right direction.)
I am trying to install Node on AWS and after installing, I am using http.createServer which is giving me the following error.
http.createServer(function (req, res) {
^
TypeError: http.createServer is not a function
at Object.<anonymous> (/home/ubuntu/test1/test1.js:4:6)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
Here is the code I am typing in my test1.js
var http = require('http');
var port = 9000;
http.createServer(function(req, res){
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello there, world\n');
}).listen(port);
console.log("Listening on port " + port);
I use fs library for reading file from system. I don't know I use this library and meet error.
I'm using PhpStorm. at line : fs.readFile() : there's a line under that, that notice me : unresolved function or method readFile(). It means IDE doesn't figure out where is this function. Nevertheless, I have checked fs.js and I see no problem.
I receive this error when running:
events.js:72
throw er; // Unhandled 'error' event
^ Error: listen EADDRINUSE
at errnoException (net.js:901:11)
at Server._listen2 (net.js:1039:14)
at listen (net.js:1061:10)
at Server.listen (net.js:1127:5)
at Object. (/home/hqt/PhpstormProjects/NodeApp/sample/AsynchronouslyReading.js:21:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
Here is my code :
var http = require('http');
var fs = require('fs');
// create http server
http.createServer(function(req, res) {
fs.readFile('helloworld.js', 'utf-8', function(err, data) {
res.writeHead(200, {'content-type' : 'text/plain'});
if (err) res.write('could not find or open file');
else res.write(data);
// ending
res.end();
});
}).listen(8124, function() {console.log('server is running at 8124');});
console.log('server is runnint at 8124 port');
Please help me figure out why. I'm using Ubuntu machine for development.
Thanks :)
That's because something else is already listening on port 8124. On Linux, you can use something like netstat -tanp | grep LISTEN | grep 8124 to see what.
I have node.js successfully installed. I have created the file
var http = require('http');
var url=require('url');
var fs=require('fs');
var io = require('socket.io');
http.createServer(function (req, res) {
fs.readFile('/var/www/nodeJS/client.html' ,
function ( err, data ) {
if ( err ) {
console.log( err );
res.writeHead(500);
return res.end( 'Error loading client.html' );
}
res.writeHead( 200 );
res.end( data );
});
}).listen(8124, '127.0.0.1');
io.listen(http);
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
The error occurs whenever I use the io object. Without io it works fine.
Error: Cannot find module 'zeparser'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/var/www/nodeJS/node_modules/socket.io/node_modules/socket.io-client/node_modules/active-x-obfuscator/index.js:1:78)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
After this I have also separately installed module zeparser. My default npm installation directory seems to be /usr/local/lib/node_modules.
I have set NODE_PATH as
export NODE_PATH="/usr/local/lib/node_modules"
but get the same error.
Then I tried to copy zeparser module to /var/www/nodeJS/node_modules. Then the error changes to
/var/www/nodeJS/node_modules/socket.io/lib/manager.js:104
server.on('error', function(err) {
^
TypeError: Object #<Object> has no method 'on'
at new Manager (/var/www/nodeJS/node_modules/socket.io/lib/manager.js:104:10)
at Object.exports.listen (/var/www/nodeJS/node_modules/socket.io/lib/socket.io.js:78:10)
at Object.<anonymous> (/var/www/nodeJS/app.js:35:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:903:3
On your root project, do:
$ sudo npm install zeparser
It resolved the problem for me.
I followed this tutorial to install the node.js on ubuntu and installation is successful. But when i type node echo-server.js i am getting following error:
module.js:340
throw err;
^
Error: Cannot find module '../../lib/ws/server'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (/home/jci/node/joyent-node-283d735/echo-server.js:2:10)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:487:10)
echo server code:
var sys = require("util")
, ws = require('../../lib/ws/server');
var server = ws.createServer({debug: true});
// Handle WebSocket Requests
server.addListener("connection", function(conn){
conn.send("Connection: "+conn.id);
conn.addListener("message", function(message){
conn.send("<"+conn.id+"> "+message);
if(message == "error"){
conn.emit("error", "test");
}
});
});
server.addListener("error", function(){
console.log(Array.prototype.join.call(arguments, ", "));
});
server.addListener("disconnected", function(conn){
server.broadcast("<"+conn.id+"> disconnected");
});
server.listen(8000);
But lib/ws/server is missing. But where do i get it from??
I don't have web socket server in my node.js installation i guess.
Thanks
Sneha