Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

var mqtt = require('mqtt'); resulting in error

Tags:

node.js

mqtt

I have installed 'node.js' and then executed 'npm install mqtt' from 'node.js' command line to install 'mqtt.js'. Now to test 'mqtt client' I am trying to execute : var mqtt = require('mqtt'); which results in error saying:

  "Error: Cannot find module 'mqtt'
   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 repl:1:12
   at REPLServer.self.eval (repl.js:110:21)
   at repl.js:249:20
   at REPLServer.self.eval (repl.js:122:7)
   at Interface.<anonymous> (repl.js:239:12)
   at Interface.EventEmitter.emit (events.js:95:17)"
like image 244
Rax Avatar asked Nov 26 '25 06:11

Rax


1 Answers

First, you need to add the MQTT library. If you have npm package manager installed on the server, you should run npm install mqtt --save

For detailed information: https://www.npmjs.com/package/mqtt

like image 77
Ismet Said Calik Avatar answered Nov 28 '25 21:11

Ismet Said Calik