nodemon app crashed : Error code- MODULE_NOT_FOUND, requirestack: [ ] - node.js

When I am running nodemon run start it is giving me the following error
I am running this on macos. Not sure if that matters or not.
ERROR
node:internal/modules/cjs/loader:926
throw err;
^
Error: Cannot find module '/Users/jarvis/Documents/Backend/mongoTelusko/run'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:923:15)
at Function.Module._load (node:internal/modules/cjs/loader:768:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
[nodemon] app crashed - waiting for file changes before starting...
This is my app.js file
const express = require('express')
const mongoose = require('mongoose')
const url = 'mongodb://localhost/AlienDBex'
enter code here
const app = express()
mongoose.connect(url, {useNewUrlParser: true})
const con = mongoose.connection
con.on('open', function(){
console.log('Connected...')
})
This is my package.json file
{
"name": "mongotelusko",
"version": "1.0.0",
"main": "app.js",
"scripts": {
"start": "nodemon app.js"
},
"author": "malay",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"mongodb": "^3.6.5",
"mongoose": "^5.12.2"
},
"devDependencies": {
"nodemon": "^2.0.7"
},
"description": ""
}

"scripts": {
"start": "nodemon app.js"
},
Since you have specified "start" script in package.json, npm start command automatically calls nodemon app.js
However, you can also run the nodemon app.js manually which also has the same effect.
Wrong: nodemon run start
Correct: nodemon app.js or npm start

You're running nodemon run start, which tells nodemon to execute run (run.js) with argument start. Did you mean to use npm run start? Hint: You can also use npm start as a shortcut.

I've got the same error while I'm trying to run the code on my Mac.
I found why it is showing me this error:
first reason is that I've installed Node.js through an installation pack downloaded from [nodejs.org][1], but I should've installed node from the Terminal.
second reason is that I found out that I was trying to run the file from a different folder. I was in folder /users/practice/file-manager/frontend - trying to run the code from file which is located in directory /users/practice/file-manager/backend - the main reason which caused this error.
As a solution that worked for me:
make sure you've installed Node.js from terminal
make sure you're in the right directory when you're trying to run the .js file.
Maybe this information helps you.

My solution after trying new files, etc... didnt work. Then starting from the beginning:
deleting node.js and clearing cache about npm (from appdata)
creating new file and being sure about path you can confirm with 'cd'
trying to re-install npm_modules at my project folder.(npm install)
Then it worked.

Related

Command failed: wmic process after updating npm in Express app

In my app.js,
const app = require("express")();
const port = 3000;
app.get("/", (req, res) => {
res.send("hello world");
});
app.listen(port, () => {
console.log("server running!");
});
This error generated after I save / update the app.js file,
(node:4196) UnhandledPromiseRejectionWarning: Error: Command failed: wmic process where (ParentProcessId=5740) get ProcessId 2> nul
at checkExecSyncError (child_process.js:630:11)
at execSync (child_process.js:666:15)
at kill (C:\Users\SANTOSH\Desktop\nodesql\node_modules\nodemon\lib\monitor\run.js:337:26)
at Function.run.kill (C:\Users\SANTOSH\Desktop\nodesql\node_modules\nodemon\lib\monitor\run.js:425:7)
at Bus.<anonymous> (C:\Users\SANTOSH\Desktop\nodesql\node_modules\nodemon\lib\monitor\run.js:495:7)
at Bus.emit (events.js:327:22)
at restartBus (C:\Users\SANTOSH\Desktop\nodesql\node_modules\nodemon\lib\monitor\watch.js:228:7)
at FSWatcher.filterAndRestart (C:\Users\SANTOSH\Desktop\nodesql\node_modules\nodemon\lib\monitor\watch.js:212:16)
at FSWatcher.emit (events.js:315:20)
at FSWatcher.emitWithAll (C:\Users\SANTOSH\Desktop\nodesql\node_modules\chokidar\index.js:540:8)
(node:4196) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
Package.json file,
{
"name": "nodesql",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "nodemon app.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"express": "^4.17.1",
"mysql2": "^2.2.5",
"sequelize": "^6.6.4",
"sequelize-cli": "^6.2.0"
},
"devDependencies": {
"nodemon": "^2.0.9"
}
}
Today I updated my npm to 7.19.1, after that I am getting this error. Otherwise, it has to do something with nodemon.
Maybe the new version of nodemon is causing this. So, I've degraded the version to 2.0.7 which is working fine for me!
npm uninstall nodemon
npm install nodemon#2.0.7 --save-dev
You check nodemon -v, if nodemon is not recognized then npm install -g nodemon -> nodemon app.js
[enter image description here][1]
[1]: https://i.stack.imgur.com/UbQLM.png
try installing nodemon verson 2.0.7 globally
first install the current version npm uninstall -g nodemon
then write the command npm i -g nodemon#2.0.7
atleast it worked for me :)
Updating your nodemon to the latest version will resolve this issue.
npm install nodemon
Running above command will update nodemon to the latest version.
The system32 folder's path was not found. As soon as I added it to the system path, it worked as it should.The problem was not with nodemon, it was my system that was missing the system32 folder's path in environment variables. System32 folder contains important operating system files that Windows needs in order to function properly. For this case the command was not automatically refreshing (nodemon).
If Not solving you can uninstall nodemone and install it again this worked for me.

Error when deploying a node.js app on a PLESK ONYX server with Phusion Passenger V. 5.3.5

I want to deploy a small node.js app on a PLESK-ONYX server - on which Phusion_Passenger / 5.3.5 is also running!
The following happens:
This works here:
var express = require ('express');
var bodyParser = require ('body-parser');
That does not work:
import express from 'express';
import bodyParser from 'body-parser';
The following error then occurs:
The Phusion Passenger application server tried to start the web application through a Passenger-internal helper tool called the "wrapper". But Passenger was unable to execute that helper tool because it encountered an internal error.
The stdout/stderr output of the subprocess so far is:
/var/www/vhosts/hosting13.netcup.net/mem3-s3.hxxx-3.de/index.js:2
import express from 'express';
^^^^^^^
How can one solve it?
Where is the problem?
Thank you for your help in advance!
Best regards
Markus
Hello, I have new findings in the meantime ...
my problem seems to be - that the highest-available node.js version in PLESK at the moment is 12.4!
In PLESK - i must start the node.js-App with a server.js-File - like this:
const app = require('./index.mjs');
const http = require('http');
http.createServer(app).listen(process.env.PORT);
My node.js-Version is V.12.4 so i must use esm like this:
require = require("esm")(module/*, options*/)
module.exports = require("./index.js")
How can i combine the 2 files in the right way?
Thanks a lot for your help!
Here is the content of "package.json":
{
"name": "mb-test-1",
"version": "1.0.0",
"description": "",
"main": "index.mjs",
"type": "module",
"scripts": {
"start": "nodemon -r esm index.mjs"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"dotenv":"^8.2.0",
"esm":"^3.2.25",
"express":"^4.17.1",
"mongoose":"^5.9.29",
"nodemon":"^2.0.7"
}
}
But unfortunately I haven't found yet - where in PLESK the start command for node.js can be edited!
Best regards
Markus
for using import from you should change type in package.json to module so add this code to the package.json
"type": "module"
Note: but export file is different between commonjs and module.
by default type is commonjs , check this article
you can also using babel module, update scripts in package.json like this
"scripts": {
"build": "rimraf dist/ && babel ./ --out-dir dist/ --ignore ./node_modules,./.babelrc,./package.json,./npm-debug.log --copy-files",
"start": "npm run build && node dist/app.js"
}
after that for running project
npm start

How to install node-hid for electron

I'm trying to get a simple electron application running that interacts with an HID device.
I am running into a lot of difficulty, I am able to install and run node-hid, just not within electron.
My package.json looks like this:
{
"name": "test-proj",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"start": "electron .",
"rebuild": "electron-rebuild --force",
"postinstall": "electron-rebuild"
},
"author": "me",
"license": "ISC",
"devDependencies": {
"electron": "^9.2.0",
"electron-rebuild": "^1.11.0"
},
"dependencies": {
"node-hid": "^1.3.0"
}
}
My main.js has the standard electron demo boilerplate code plus some HID calls:
const {app, BrowserWindow, ipcMain} = require('electron');
var HID = require('node-hid');
var device = new HID.HID(5824, 1500);
// Standard electron app window stuff
When trying to run the app I immediately get an error on new HID.HID():
Error: Module did not self-register: '\\?\C:\Users\Nathan\Desktop\carriage_return_app\node_modules\node-hid\build\Release\HID.node'.
at process.func [as dlopen] (electron/js2c/asar.js:140:31)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1034:18)
at Object.func [as .node] (electron/js2c/asar.js:140:31)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Module._load (internal/modules/cjs/loader.js:727:14)
at Function.Module._load (electron/js2c/asar.js:769:28)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at bindings (C:\Users\Nathan\Desktop\carriage_return_app\node_modules\bindings\bindings.js:112:48)
at loadBinding (C:\Users\Nathan\Desktop\carriage_return_app\node_modules\node-hid\nodehid.js:25:42)
Looking around I have seen a few examples of how to install node-hid and use it in electron, but none have helped me.
I have followed the electron-rebuild instructions here: https://www.electronjs.org/docs/tutorial/using-native-node-modules
I have also followed the instructions and copied the examples from here: https://github.com/node-hid/node-hid#electron-projects-using-node-hid
No luck. I get module did not self-register every time. node-hid is supposed to support electron and I don't see other people complaining.
Anyone come across this or have ideas to fix the issue?
The problem has been solved, so I will mark this as answered. I think I would still like more information on WHY though.
The hint came from building the two example projects:
https://github.com/todbot/electron-hid-toy
https://github.com/todbot/electron-hid-test
Running the first item, electron-hid-test worked off the bat. Adding electron-builder as a dependency and adding "postinstall": "electron-builder install-app-deps" as a script solved the issue in my project, I don't want electron-builder yet but at least it indicated that node-hid can work with electron given a specific setup.
The second item also worked, but not with:
npm install
npm rebuild
npm start
Instead it was specifically required to add the run command to the rebuild command:
npm install
npm run rebuild
npm start
After that, it works.
Any insights as to why this behaves differently?

Lowdb on Node.js failing with permissions error

I am attempting to implement the lowdb NPM package for use with node.js, but I am running into permissions errors. I have tried all of the examples listed in the readme located at https://github.com/typicode/lowdb/tree/master/examples, but all are returning the same error.
For ease, here is the specific code I tried running from the node CLI:
const low = require('lowdb')
const FileSync = require('lowdb/adapters/FileSync')
const adapter = new FileSync('db.json')
const db = low(adapter)
db.defaults({ posts: [] })
.write()
const result = db.get('posts')
.push({ name: process.argv[2] })
.write()
console.log(result)
I am executing with this command:
$ node cli.js hello
This should be the result:
# [ { title: 'hello' } ]
Instead I receive this error:
[server]$ node cli.js hello
fs.js:549
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^
Error: EACCES: permission denied, open 'db.json'
at Error (native)
at Object.fs.openSync (fs.js:549:18)
at fs.writeFileSync (fs.js:1156:15)
at FileSync.read (/home/nodeadmin/datadir/estimup/node_modules/lowdb/adapters/FileSync.js:46:9)
at LodashWrapper.db.read (/home/nodeadmin/datadir/estimup/node_modules/lowdb/lib/main.js:32:21)
at module.exports (/home/nodeadmin/datadir/estimup/node_modules/lowdb/lib/main.js:51:13)
at Object.<anonymous> (/home/nodeadmin/datadir/estimup/cli.js:5:12)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
I have attempted creating the db.json file manually in advance and gave it chmod 644 permissions, still to no avail.
I found a working solution that, while not perfect, I will share to help those who may just need it working for development reasons.
The underlying issue is that node needs the rights to create/modify files. An easy way to make this work is simply: $ sudo node cli.js
I wanted nodemon to run cli.js however. The problem there was that I was receiving a command not found error when attempting $ sudo nodemon cli.js. This is because of a separate problem with my nodemon installation that I have yet to figure out.
The workaround that worked for me here was found in an answer to this stack: nodemon not found in npm
Specifically, add the following to package.json:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon cli.js"
}
Then $ sudo npm start
Now nodemon is running my application with elevated privileges and I can move on with my project.

Have you got nightmareJS working properley on c9.io IDE

NightmareJS on c9.io is literally a nightmare.
i cannot get it to work at all i am going to run through the whole process from start to finish.
Step 1
I create a new workspace
Hosted
Node.js
Step 2
Start Editing my new workspace
I open Package.json and add what i need heres my file.
{
"name": "chat-example",
"version": "0.0.0",
"description": "A chat example to showcase how to use `socket.io` with a static `express` server",
"main": "server.js",
"repository": "",
"author": "Mostafa Eweda <mostafa#c9.io>",
"dependencies": {
"async": "~0.2.8",
"express": "~3.2.4",
"socket.io": "~0.9.14",
"phantomjs": "*",
"casperjs": "*",
"nightmarejs": "*",
"utils": "*",
"crypto": "*"
}
}
i then run 'npm install' in the console.
Step 3
this is where it does not work i try all theses diffrent commands to get the examples running and the errors i get.
#stackoverflow:~/828481 $ cd node_modules/nightmarejs/examples/
#stackoverflow:~/828481/node_modules/nightmarejs/examples $ node server.js casper.js
Error: Cannot find module 'crypto'
phantomjs://bootstrap.js:289
phantomjs://bootstrap.js:254 in require
/var/lib/stickshift/5345392f50044693d40008de/app-root/data/828481/node_modules/utils/utils.js:7
/var/lib/stickshift/5345392f50044693d40008de/app-root/data/828481/node_modules/utils/utils.js:117
/var/lib/stickshift/5345392f50044693d40008de/app-root/data/828481/node_modules/utils/utils.js:118
Error: Cannot find module 'casper'
phantomjs://bootstrap.js:289
phantomjs://bootstrap.js:254 in require
/var/lib/stickshift/5345392f50044693d40008de/app-root/data/828481/node_modules/nightmarejs/lib/nightmareClient.js:4
/var/lib/stickshift/5345392f50044693d40008de/app-root/data/828481/node_modules/nightmarejs/lib/nightmareClient.js:83
TypeError: 'undefined' is not a function (evaluating 'require(phantom.args[3].slice(13)+'nightmareClient.js').Nightmare({
exitOnError: false
})')
/var/lib/stickshift/5345392f50044693d40008de/app-root/data/828481/node_modules/nightmarejs/lib/nightmareTest.js:16
I have it working. I also had trouble at first. I tried downloading the prebuilt package, but I can't seem to get that working. I ended up just adding the following to my package.json file and ran npm update and all was well:
"nightmare": "^1.5.0",
"phantomjs": "~1.9.7"
Probably they've updated the npm repo and everything since you've posted this. I bet it was frustrating. I don't have those examples in my install, but I would guess you could run them if you had all of the right pre-req's installed.

Resources