This example is designed to help you get familiarized with running Node.js on a BrightSign player. It demonstrates how to run a Node.js server directly on the player that can serve both static files and fetch device information. Additionally, it introduces tools and configurations that go beyond the basics covered in starter examples.
The core Node.js application is defined in app.js, which:
- Serves static files from the
/storage/sd/directory - Provides device information via a REST API endpoint
- Includes proper content-type handling for common file types
This example includes a built-in static file server that serves files from the /storage/sd/ directory. The server:
- Automatically serves
index.htmlwhen accessing the root URL (/) - Handles common file types with appropriate content-type headers (HTML, CSS, JavaScript, images)
- Returns 404 errors for files that don't exist
- Create an
index.htmlfile in your SD card root:
<!DOCTYPE html>
<html>
<head>
<title>My BrightSign App</title>
</head>
<body>
<h1>Hello from BrightSign!</h1>
<div id="device-info"></div>
<script>
// Fetch and display device info
fetch("/api/device-info")
.then((response) => response.json())
.then((data) => {
document.getElementById(
"device-info"
).innerHTML = `Model: ${data.model}<br>
OS Version: ${data.osVersion}`;
});
</script>
</body>
</html>-
Access your content:
- Main page:
http://<player-ip>:13131/ - Individual files:
http://<player-ip>:13131/styles.css,http://<player-ip>:13131/images/logo.png, etc.
- Main page:
-
Supported file types:
- HTML (
.html):text/html - JavaScript (
.js):text/javascript - CSS (
.css):text/css - JSON (
.json):application/json - Images (
.png,.jpg):image/png,image/jpeg - Other files:
text/plain
- HTML (
Ensure that Node.js is installed on your machine. From your project directory, install the necessary dependencies by running the following command:
npm installNext, build and bundle the application:
npm run buildAfter the application is bundled, you need to transfer the required files to your BrightSign player:
- Copy the
distfolder to the SD card - Place the
autorun.brsfile at the root of the SD card - Place any static files (HTML, CSS, images) you want to serve in the root of the SD card
- Insert the SD card into the player
- Reboot the player
BrightSign's player CLI: player-CLI. To deploy this app with the CLI:
Configure the CLI by choosing a name for your player and passing your player's information:
bsc local player --add --player playerName --ip ip-address --user username --pass password --storage sdThis is an example command for pushing files to your player:
bsc local file --upload --player playerName --file ./path-to-your-file --destination sd/path-on-playerAlternatively, there is a script that can be run that is configured for this application:
npm run upload --playerName=playerNameOnce the player is running, you can access the Node.js server from a web browser. Make sure your computer is connected to the same network as the BrightSign player.
-
Static Files:
http://<player-ip>:13131/Serves files from the
/storage/sd/directory. The root URL (/) will serveindex.htmlif present. -
Device Info API:
http://<player-ip>:13131/api/device-infoReturns JSON with device information like model, OS version, and serial number.
This example is equipped with basic mocking to make testing easier with local development. In the __mocks__ directory, there is a deviceinfo.js file which defines mock values when the application is run in a development environment.
To run the test(s) located in App.test.js, execute the following:
npm run test