Node.js - Command npm run dev is stuck on message "Compilation complete. Watching for file changes" - node.js

When I launch npm run dev on my project, the process is stuck on the message below:
Compilation complete. Watching for file changes
and the server is not started.
I have the problem only on my Windows. When I launch the same command on my Ubuntu virtual machine, the server start as expected.
Do you know what how could I investigate more, have some logs or indications about the "error" ?
Thank you very much.

can you post your package.json file?
it is important, your script part is definded like that:
{
"name": "snail",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "nodemon app.js",
"dev":"node app.js"
},
"dependencies": {
"body-parser": "^1.19.0",
"cookie-parser": "~1.4.4",
"debug": "~2.6.9",
}
}
app.js is the filename of yout startfile.

Related

Can't run node express on centos server

I am trying to run an express app that I installed using express --view pug urltracker. I also executed npm install to install all dependencies.
When I start it on my laptop localhost using DEBUG=urltracker:* && npm start
it perfectly starts on localhost:3000 and my app runs smoothly but when I install it on centos 7 server, the same gets stuck at [nodemon] starting `node ./bin/www and nothing happens afterwards.
I tried running it like this as well DEBUG=backend ./bin/www but it says -bash: ./bin/www: Permission denied OR sudo: ./bin/www: command not found
I can execute a normal file like node app.js and it works fine but when it comes to running it as server, it doesn't work.
Here's my package.json
{
"name": "urltracker",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "nodemon ./bin/www"
},
"dependencies": {
"body-parser": "~1.18.2",
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"express": "~4.15.5",
"morgan": "~1.9.0",
"pug": "2.0.0-beta11",
"serve-favicon": "~2.4.5",
"puppeteer": "^1.6.2",
"puppeteer-select": "^1.0.3"
},
"devDependencies": {
"eslint-plugin-mocha": "^4.11.0",
"file-system": "^2.2.2",
"jest": "^21.2.1",
"js-comments": "^0.5.4",
"lodash": "^4.17.13"
}
}
I also tried it with running node supervisor using supervisor ./bin/www
but it says
Starting child process with 'node ./bin/www'
Watching directory '/home/admin/web/example.com/node/projects' for changes.
Press rs for restarting the process.
I also tried changing the port to 3001 in ./bin/www like this - server.listen('3001', '0.0.0.0');
but nothing works. Help.
Nodemon is not listed in your dependencies list in package.json and on the centos server nodemon is not present.
Please add the nodemon dependency in the package.json and then run npm i
or change the start script from "start": "nodemon ./bin/www" to "start": "node ./bin/www"

Discord bot sends response twice

I'm coding a discord.js bot, and whenever I send a command, it gives a response twice. I've concluded it's because I have too many instances running. I try to delete the instances, but it doesn't delete. Sometimes it says "Some instances could not be deleted", and sometimes it doesn't delete at all.
And through Terminal
SERVICE VERSION ID VM_STATUS DEBUG_MODE
default 20191208t223728 aef-default-20191208t223728-0l57 RUNNING
default 20191208t223728 aef-default-20191208t223728-jb53 RUNNING
default 20191208t223728 aef-default-20191208t223728-wpgm RUNNING
This is what the messages look like. There should only be one message, not three.
Here is what my package.json looks like:
"name": "discord-bot",
"version": "1.0.0",
"description": "Custom bot for Chinese Discord server.",
"main": "index.js",
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js",
"build": "next build"
},
"keywords": [],
"author": "Jacob Villorente",
"license": "ISC",
"dependencies": {
"discord.js": "^11.4.2",
"discord.js-commando": "^0.10.0",
"dotenv": "^7.0.0",
"express": "^4.17.1",
"node-fetch": "^2.6.0",
"ytdl-core": "^1.0.3"
},
"devDependencies": {
"nodemon": "^1.18.11"
}
}
Any help would be greatly appreciated. Thank you
There are two ways to resolve your problem.
The first one, and the better, is to use grep to get all your node processes who are running on your machine:
ps -ef | grep node
Then, you will be able to kill them with kill command.
The second way is to change your discord bot token. All the instances will be errored so you're sure there's no instance launched anymore.

Unable to start the server

I am trying to use nodemon for auto-starting the server whenever a change is made in the local file, but I get the following error.
(Click image to enlarge)
package.json
{
"name": "myapp",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "if [[ $NODE_ENV == 'production' ]]; then node ./bin/www; else nodemon ./bin/www; fi"
},
"dependencies": {
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"express": "~4.16.0",
"http-errors": "~1.6.2",
"morgan": "~1.9.0",
"pug": "^2.0.3"
},
"devDependencies": {
"nodemon": "^1.18.10"
}
}
It looks like the start script uses Bash scripting syntax, but the screenshot is of a Windows command terminal. The error is because Windows doesn't understand the Bash syntax.
To immediately get you running, you can just change the start script to just nodemon ./bin/www. You'll then want to either figure out the correct syntax, or add another script for the production start script, like "start-prod": "node ./bin/www"' and runnpm run start-prod` in production.

How to install man on Heroku

My app needs the package: man, but by default it's not installed on the heroku/nodejs buildpack.
So according to the documentation, heroku/heroku-buildpack-apt is the tool for the job when your app needs additional apt dependencies.
I assigned the new buildpack and added a Aptfile to the root of the project with one line:
man
Here is my full package.json
{
"name": "unix-translator",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www",
"test": "mocha --exit"
},
"dependencies": {
"body-parser": "~1.18.2",
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"express": "~4.15.5",
"jade": "~1.11.0",
"morgan": "~1.9.0",
"node-dev": "^3.1.3",
"serve-favicon": "~2.4.5",
"dateTools": "file:lib/unix-command"
},
"devDependencies": {
"chai": "^4.1.2",
"mocha": "^4.1.0"
}
}
Here's my Procfile:
web: node ./bin/www
This gets the dependency successfully installed because I see it when I run which man now. But it doesn't work.
I get this error when I try to use the man program:
~ $ man cat
man: error while loading shared libraries: libmandb-2.7.5.so: cannot open shared object file: No such file or directory
I did found this blog post and this other blog post which both suggest the problem related to permissions and the location of files... I SSHed into my dyno and ran: /sbin/ldconfig -v and it eventually threw this error:
/sbin/ldconfig.real: Can't create temporary cache file /etc/ld.so.cache~: Read-only file system
^ The command needs to be run with sudo and that's not available inside a dyno. :-(
So I'm stuck again.
Not 100% sure, but this might be worth a shot:
Replace the "prestart" in your package.json with heroku-prebuild (or heroku-postbuild), as follows:
"scripts": {
"start": "node ./bin/www",
"test": "mocha --exit",
"heroku-prebuild": "apt-get update && apt-get install man"
},
You had this in "prestart", which means it gets executed when you run npm start.
However, from your question, it looks like you are accessing a one-off Heroku dyno (e.g. with "heroku run bash"), and then trying to run "man cat" therein. So when you do that, you are not running "npm start" at all on your dyno.
By putting the "apt-get" in one of the Heroku specific build steps, it executes when your slug gets built, and hence whatever you install should be available on any dyno in your app (including one-off dynos).

How can I publish a nodJS app on aws?

I'm using a free tier version of aws cloud, and have some trouble with loading up a nodeJs Application. I 've tried to follow the documentation of aws but it didn't work unfortunately. I choose the Elastic BeanStalk, from the services, and create a new Application. I choose nodeJs for the preconfigured platform of course. I make a zip with my app, and I really pay attention, to not have any parent folder above package.json, and app.js . As you can see on the picture above, I have a folder "public" which contains additional folders (css,img, javascript code). When I try to upload the project, I get an error message.
"Failed to find package.json. Node.js may have issues starting. Verify package.json is valid or place code in a file named server.js or app.js." In the project view I've got a health status "degraded", and an other error code: "i-045ac359227e3a9ae" Severe
I 've tried many php projects on this server, and everything worked fine,but I can't make it work with Node. Could you help me out please?
package.json:
{
"name": "kutyapplikacio",
"version": "1.0.0",
"description": "Egy alkalmazás kutyáknak és gazdáiknak",
"main": "server.js",
"scripts": {
"test": "test",
"start": "node server.js"
},
"author": "sethdevelop",
"license": "ISC",
"dependencies": {
"body-parser": "^1.17.2",
"express": "^4.15.3",
"express-mailer": "^0.3.1",
"express-mysql": "0.0.1",
"express-validator": "^3.2.0",
"mysql": "^2.13.0",
"nodemailer": "^4.0.1",
"nodemailer-smtp-transport": "^2.7.4"
}
}
The error message you wrote is : "Failed to find package.json. Node.js may have issues starting. Verify package.json is valid or place code in a file named server.js or app.js."
From the folder I only see you have app.js file.
And in your package.json, there are server.js:
"main": "server.js",
"scripts": {
"test": "test",
"start": "node server.js"
}
Perhaps you should change server.js to app.js ?
Update
Since you mentioned they have the same name:
could it be you zipped the folder instead of zipped the files ?
Same problem has been discussed here:
https://forums.aws.amazon.com/message.jspa?messageID=477087
https://forums.aws.amazon.com/thread.jspa?threadID=130140

Resources