#Error: Cannot find module 'mqtt' but it is installed
1 messages · Page 1 of 1 (latest)
root@raspberrypi:/home/pi# npm list -g
/usr/local/lib
├── corepack@0.17.0
├── mqtt@4.3.7
├── n@2.1.12
├── node-gyp@3.7.0
├── node-red@3.0.2
└── npm@9.6.5
I also did npm install in the mqtt package folder
Im so confused
If u ask what code the furkan.js is, it is this ```js
const mqtt = require('mqtt')
const client = mqtt.connect('mqtt://test.mosquitto.org')
client.on('connect', function () {
client.subscribe('presence', function (err) {
if (!err) {
client.publish('presence', 'Hello mqtt')
}
})
})
client.on('message', function (topic, message) {
// message is Buffer
console.log(message.toString())
client.end()
})
It is just an example code to test if its working
And for some fking reason it says mqtt module not found but its clearly installed??
why is it installed globally though?
that probably isn't the issue but it should be installed locally to the project
I tried both ways, lots of articles say do globally
not global woul be just without -g i guess?
yes
what defines a "project"
sorry im new to js and node
I just have this file i want to make run 
but as u said it shouldnt be the issue anyway
the package's readme says to install it locally 
do i just run npm install mqtt in the same folder where the .js file is?
a project is a directory which holds your package.json and node_modules and whatever source and asset files you may have, ie basically your entire project is there
it's created automatically if you do npm install locally or if you do npm init
i mean, you could, but i don't think you're supposed to have projects in /usr/local/bin
thanks
