0

required module not found when running nodejs on bs player

I'm testing the nodejs exmaple in the docs.  http://docs.brightsign.biz/display/DOC/Node.js

So I tested to replace the nodejs code with hello world for nodejs express: http://expressjs.com/en/starter/hello-world.html

When starting up the project I get:

"[ERROR]  [source module.js:340]: Uncaught Error: Cannot find module 'express'"

I have copied my node_modules directory to the sd card and it is located at the same location as the index.html which is the file containing the javascript code.

Is it only built in modules that are available for node on Brightsign player?

 

 

4 comments

  • 0
    Avatar
    par

    I realized that I can't find my own modules created (when splitting up my code in smaller files).

    For example:

    I have the following file structure:

    src/

        server.js

        Utils.js

     

    When trying to access Utils.js from server.js with "const Utils = required('./Utils); then NodeJs cant find the module.

    I guess that it is because NodeJs seems to be run from '/'.

    Is there a way around this? Would be good to be able to split up the code. But I don't want to have to stick the complete path from root to the file to include.

    I have tested to add __dirname to the required path. But it seems like it is returning '/' on my player and not the path to the running module.

     

  • 0
    Avatar
    Lyndon

     

    I'm checking with one of our developers on this. I should have an answer on Monday

  • 0
    Avatar
    Lyndon

    Here's what my colleague recommends:

     

    <html>

     

      <head>

        <script>

          var storagePrefix = '/storage/sd';

          var app = require(storagePrefix + '/app');

          var bsUtils = require(storagePrefix + '/bs-utils');

  • 0
    Avatar
    par

    Thanks! That works.

Please sign in to leave a comment.