NODE JS NPM Node Package Manager

Discussion in 'ASP.NET / ASP.NET Core' started by eveP, May 28, 2013.

  1. I am a bit confused about how to run NODE commands in my shared hosting environment. I am new to NODE JS, and I am trying to get a simple web socket sample running in this environment. I added the web.config nodes that send JS files in a particular folder to NODE to process. However, I need to install some node packages before I run the the chat sample.

    How do I install NODE packages from a command line? Am I supposed to put them in a file and run them? Do you have any samples for setting up a NODE JS Chat Web-socket on DiscountASP.NET?

    I have attached the simple chat sample that I am trying to install, in case you want to preview the code or installation instructions involving the NPM.
     

    Attached Files:

  2. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

    Please make sure your account is on Windows 2012/IIS8. You'll also need to open up a support ticket to request that WEBSOCKETS be enabled for your account. You can then try out your code.
     
  3. All Set

    Yes my environment is setup for both of those things... But The instructions say to run:

    $ npm install

    And then...

    $ node server.js

    I am pretty sure I run server.js, just by running the file now that I have the directory setup to send js files to NODE.

    However, How to I run the $ npm install in the Discount ASP.NET Environment?
     
  4. The node.js engine is already installed on the server, if you need to install something directly on the server, I'm afraid we will not be able to, due to security and stability reasons.
    What packages are you speaking of?
    And what error are you exactly getting?
    Is there a way we can see the error for ourselves?
     
  5. Hello,

    I am just trying to get a simple chat sample ws:// websocket running using Node.js. I have the sample file and instructions outlined below. I feel that this should be basic enough to run in this environment. Is there something here that you do not support?

    Essentially we need the Node Package Manager I think? Do you have that installed?

    =========================================
    Instructions
    =========================================
    REQUIREMENTS
    ============
    * nodejs (version 0.8.x)
    * npm

    SETUP
    =====
    # from this directory
    $ npm install

    RUN
    ===
    $ node server.js


    =========================================
    Web.config... I think this is setup correctly and working
    =========================================

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    <system.webServer>
    <handlers>
    <add name="iisnode" path="*.js" verb="*" modules="iisnode" />
    </handlers>
    </system.webServer>
    </configuration>

    =========================================
    This is the package... in package.js Something to do with NPM
    =========================================
    {
    "name": "chatserver",
    "version": "0.0.1",
    "description": "An example chat server using basic web sockets.",
    "author": "Jeremy Osborne <[email protected]>",
    "dependencies": {
    "colors": "0.6.x",
    "fs-extra": "0.2.x",
    "websocket": "1.0.7"
    },
    "devDependencies": {
    },
    "engine": "node >= 0.8.x"
    }


    =========================================
    server.js...
    Here is the Node JS websocket. It is a sample from another source
    =========================================



    var WebSocketServer = require('websocket').server;
    var http = require('http');
    require('colors');
    var PORT = 8080;

    var server = http.createServer(function(request, response) {
    console.log((new Date()) + ' Received request for ' + request.url);
    response.writeHead(404);
    response.end();
    });
    server.listen(PORT, function() {
    console.log("");
    console.log(((new Date()) + ' Server is listening on port ' + PORT).inverse);
    console.log("");
    });



    var wsServer = new WebSocketServer({
    httpServer : server,
    autoAcceptConnections : true,
    });

    var connectionPool = {
    connections: [],
    add: function(connection) {
    this.connections.push(connection);

    console.log((new Date() + ' Connection accepted from: '
    + connection.remoteAddress).magenta);
    this.logDiagnostics();

    this.broadcastUsers();
    },
    remove: function(connection) {
    this.connections = this.connections.filter(function(test) {
    return connection !== test;
    });

    console.log(((new Date()) + ' Connection '
    + connection.remoteAddress + ' disconnected.').magenta.inverse);
    this.logDiagnostics();

    this.broadcastUsers();
    },
    broadcast: function(connection, message) {
    var from = (connection && connection.remoteAddress) ?
    connection.remoteAddress : "unknown";

    for (var i = 0; i < this.connections.length; i++) {
    if (this.connections !== connection) {
    this.connections.sendUTF(JSON.stringify({
    "broadcast": {
    "message": message,
    "from": from,
    },
    }));
    }
    }
    },
    broadcastUsers: function() {
    var userList = this.connections.map(function(c) {
    return c.remoteAddress
    });
    for (var i = 0; i < this.connections.length; i++) {
    this.connections.sendUTF(JSON.stringify({
    "users": userList
    }));
    }
    },
    logDiagnostics: function() {
    console.log("Num current connections == " + this.connections.length);
    console.log("Connection addresses: " + this.connections.map(function(c) {
    return c.remoteAddress
    }).join(", "));
    },
    };

    wsServer.on('connect', function(connection) {

    connectionPool.add(connection);

    connection.on('message', function(message) {
    if (message.type === 'utf8') {
    console.log(('('+connection.remoteAddress+') sent: ' + message.utf8Data).blue);
    connectionPool.broadcast(connection, message.utf8Data);
    }
    });

    connection.on('close', function(reasonCode, description) {
    connectionPool.remove(connection);
    });
    });


    =========================================
    All of these files are located in at:
    http://www.baselayertraining.com/WebSockets/Chat/
    =========================================

    If I run:
    http://www.baselayertraining.com/WebSockets/Chat/ws_server.js

    I get an error:

    iisnode encountered an error when processing the request.

    HRESULT: 0x2
    HTTP status: 500
    HTTP reason: Internal Server Error
    You are receiving this HTTP 200 response because system.webServer/iisnode/@devErrorsEnabled configuration setting is 'true'.

    In addition to the log of stdout and stderr of the node.exe process, consider using debugging and ETW traces to further diagnose the problem.

    The last 64k of the output generated by the node.exe process to stdout and stderr is shown below:

    module.js:337
    throw new Error("Cannot find module '" + request + "'");
    ^
    Error: Cannot find module 'websocket'
    at Function._resolveFilename (module.js:337:11)
    at Function._load (module.js:279:25)
    at Module.require (module.js:359:17)
    at require (module.js:375:17)
    at Object.<anonymous> (E:\web\moonhighway\htdocs\WebSockets\Chat\ws_server.js:2:23)
    at Module._compile (module.js:446:26)
    at Object..js (module.js:464:10)
    at Module.load (module.js:353:31)
    at Function._load (module.js:311:12)
    at Array.0 (module.js:484:10)

    ==============================
     
  6. FrankC

    FrankC DiscountASP.NET Staff

Share This Page