From 5e28005d756782df90657d688842a8c7999671c0 Mon Sep 17 00:00:00 2001 From: ry-yamafuji Date: Wed, 12 Jun 2024 06:58:45 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=BD=E3=83=BC=E3=82=B9=E3=82=A2=E3=83=83?= =?UTF-8?q?=E3=83=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 20 ++++++++++++++++++++ README.md | 25 +++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..322e051 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +# Use the official Node.js image with Alpine +FROM node:alpine + +# Create and change to the app directory +WORKDIR /usr/src/app + +# Copy package.json and package-lock.json files to the working directory +COPY package*.json ./ + +# Install the dependencies +RUN npm install + +# Copy the application source +COPY . . + +# Expose the MQTT port +EXPOSE 1883 + +# Run the MQTT broker +CMD ["node", "broker.js"] diff --git a/README.md b/README.md index e69de29..68bb9aa 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,25 @@ +npm install aedes --save +npm install aedes-cli --global + + +``` +const aedes = require('aedes')(); +const server = require('net').createServer(aedes.handle); +const port = 1883; + +server.listen(port, function () { + console.log('Aedes broker started and listening on port ', port); +}); + +aedes.on('client', function (client) { + console.log('Client Connected:', client.id); +}); + +aedes.on('clientDisconnect', function (client) { + console.log('Client Disconnected:', client.id); +}); + +aedes.on('publish', function (packet, client) { + console.log('Published:', packet.payload.toString()); +}); +``` \ No newline at end of file