Node & React - npm start - is running BUT localhost:3000 "cant be reached" - node.js

(having node version 12 and npm version 6)
Backend: Node.js
Front: React.js
i cloned repository
cd into the directory
ran
npm install (installing dependencies etc...)
and when i ran
npm start
and i get
[Ben#Mac:~/Desktop/test]$ npm start
> answers-entry-level-exam#1.0.0 start /Users/Ben/Desktop/test
> lerna run start --parallel
lerna notice cli v3.22.1
lerna info Executing command in 1 package: "npm run start"
#ans-exam/server: > #ans-exam/server#1.0.0 start
/Users/Ben/Desktop/test/server
#ans-exam/server: > ts-node-dev index.ts
#ans-exam/server: Using ts-node version 8.5.2, typescript version 3.7.2
#ans-exam/server: server running 3232
which seems like the server is running okay
but localhost:3000 cant be reached
not opening anything
the first time it did open and there was a MacOS popup on the right side of the screen related to node ( i think that is the issue but cant figure out how to fix)
my package.json:
{
"name": "answers-entry-level-exam",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"b": "npm run bootstrap",
"bootstrap": "lerna bootstrap",
"test": "echo \"Error: no test specified\" && exit 1",
"start": "lerna run start --parallel",
"postinstall": "npm run bootstrap"
},
"author": "",
"license": "ISC",
"devDependencies": {
"lerna": "^3.22.1"
}
}
Thanks!

I cloned again the repo and it fixed that
Cheers to all those who tried to help :)

Try localhost:3232. I see in your output server running 3232

Related

I am facing problem in running the backend of a github repository

I hope you are doing great,
I am trying to cloning one of the Github repository,
here's the link to repo:
https://github.com/thevarunjain/job-portal-mern-stack
I've done everything according to my knowledge, I've run the MongoDB, install all the dependencies by npm I, frontend is running successfully but whenever I run the backend "npm run dev" am getting this error:
** ./node_modules/.bin/nodemon src/index.js
'.' is not recognized as an internal or external command,
operable program or batch file. **
here's the script of package.json:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js",
"dev": "./node_modules/.bin/nodemon src/index.js"
}
Please let me know how can I fix this issue, thanks!

Nodemon ''npm' is not recognized as an internal or external command

I realize that this is most likely a duplicate question. I'm new to nodemon and I'm trying to establish a server for a Vue JS project with nodemon. I'm trying to run eslint with nodemon and can't figure out why I keep getting the error message. If I remove npm after --exec it will tell me ''run' is not recognized, and if I remove that I will get ''lint' is not recognized and so on.
My package.json file:
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon src/app.js --exec 'npm run lint && node'",
"lint": "eslint **/*.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"eslint": "^4.16.0",
"nodemon": "^1.14.12"
}
}
I have also tried this code in my start scripts:
"scripts" : {
"start": "./node_modules/nodemon/bin/nodemon.js src/app.js --exec 'npm run lint && node'",
"lint": "./nodemodules/.bin/eslint **/*.js"
}
Where is tells me that "." is not recognized as an internal external command.
I've installed nodemon into my server folder and in the project directory as well as globally. I have done the same with eslint as well.
i had the same problem today. did some google stuff and found that this is not working anymore. so i tried this
"scripts": {
"prestart": "npm run lint ",
"start": "nodemon src/app.js ",
"lint": "./node_modules/.bin/eslint src/*.js"
},
when you npm start node will run the pre-start script before the start script.Once a file being updated this pre-start wont run by the nodemon.So for that we have to call the nodemon events.So create a nodemon.json on root folder and paste following.
{
"events": {
"restart": "npm run lint"
}
}
you can read more nodemon config options from here nodemon config .There are more nodemon events.you can read them from here event restart
PS:im very new to this. :)
EDIT1:
You can use as follows. this dont need a nodemon config;
"scripts": {
"start": "node src/app.js",
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon src/app.js --exec \"npm run lint --fix && node\"",
"lint": "eslint --fix **/*.js "
}
for run use npm run dev it will run es lint + nodemon. this is for windows cmd command.if you are using bash terminal, remove \ in "dev" ;
"dev": "nodemon src/app.js --exec "npm run lint --fix && node""
I had the same problem.
For some reason you can't use simple quotes in npm scripts.
Use escaped double quotes instead. This should work:
"start": "nodemon src/app.js --exec \"npm run lint && node\""
install it globally for making it available on path.
npm i -g nodemon
or if using yarn
yarn global add nodemon
and if you tried this approach and it didn't work.
you should try running it locally..
you have to create a script in your package.json like this
"script": {
"server" : "nodemon scriptFile.js" //name of the file you want to run
}
then use,
npm run server
but before it,
install nodemon locally.
check it, if it is available on package.json

npm: how to run test & lint on each change?

I am using a bare npm ( no grunt/gulp) approach to develop my new MEAN project.
My config is like the following:
File package.json:
...
"start": "nodemon ./bin/www",
"lint": "jshint **/*.js",
"test": "mocha --recursive",
"dependencies": {
...
},
"devDependencies": {
...
},
Before starting, I run an npm start and nodemon starts monitoring my project tree for changes, triggering a restart after each source file change.
So far so good.
But what if I'd like to include - say - the lint and/or the test stages on each restart?
I didn't find any clue nor in the nodemon page nor in the npm one...
So you should have a definition of the start in your package.json to first run lint, then test then the actual run server.
You can find an example in following post:
http://substack.net/task_automation_with_npm_run
you should run the 'npm run monitor' command to start the monitoring and the restart should call the npm run start script.
but basically you want to have (based on your package.json)
"scripts": {
"start": "npm run lint & npm run test & node ./myfile.js",
"lint": "jshint **/*.js",
"test": "mocha --recursive",
"monitor": "nodemon ./bin/www"
.....

Execute node http-server locally from cli

If I install http-server locally (without -g flag) how can I run it with local directory as root directory?
In my root project directory I have a node_modules folder, If I want to execute http-server I need to execute $node ./node_modules/http-server/bin/http-server.
I wish to launch http-server with a command like $npm http-server.... If I use $npm start http-server, the server start without ./ as root.
You can call the executable that sits in the module's bin folder like so:
> ./node_modules/http-server/bin/http-server
If you want to do it with an npm command, you can put that in your package.json's scripts collection:
{
"name": "tmp",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start":"./node_modules/http-server/bin/http-server",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Then you can just run
> npm start

Watcher automation in Mocha

I would like to achieve automation of motcha --watcher feature using package.json file without globally installing mocha.
One of npm features is to allow add custom scripts into npm command. Previously I configured test runner successfully and I can type in bash now:
npm test
Everything works fine, so I would like also do something similar because
./node_modules/mocha/bin/mocha --watch app.js test.js"
is not too efective.
My goal is to run mocha watcher by typing in bash:
npm watch
Unfortunately watcher doesn't run - instead I see standard output of npm command without parameters. It looks like my custom script wasn't registered by npm.
Here is my actual package.json file
{
"name": "screencast",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha test.js", // works properly after typing 'npm test'
"watch": "mocha --watch app.js test.js" // Syntax looks ok, but command 'npm watch' d
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.10.6"
},
"devDependencies": {
"mocha": "^2.0.1",
"supertest": "^0.15.0"
}
}
Anyone had this issue before?
For a 'custom' script like watch, you have to do npm run watch instead of npm watch

Resources