Running json-server and protractor test on both Windows and Linux - javascript

I would like to run json-server and then a protractor test on both Windows and Linux. For now, I have two configurations, one for Linux and one for Windows. Relevant part from packages.json:
"scripts": {
"start": "json-server --watch testdb.json --static ./src",
"e2e-win": "npm run protractor",
"e2e-linux": "npm run protractor",
"pree2e-win": "start /b npm start",
"pree2e-linux": "npm start &",
...
}
The json-server is started as a background process and then the protractor executes. Is there any way how to do this in an OS agnostic way? I simply want one target e2e.

I'd the package say concurrently is a good match for your example, this way in the package.json you can simply do in the scripts section (taken from one tutorial I'm going through):
"ng": "ng",
"serve": "ng serve --proxy-conf proxy.conf.json",
"api": "json-server --watch api/data.json --routes api/routes.json",
"start_custom": "concurrently \"npm run api \" \"npm run serve\""
Finally just run on the command line npm run start_custom

Related

nodemon app crashed - waiting for file changes before starting... HOW TO MAKE IT RESTART ANYWAY?

From time to time it does happen, but restarting the node bypass this. I really dont have how to debug and see the actual error and the site needs to be online anyway.
I wish to know a way to restart the server whet this error happens, without having to change a file or anything like that.
I know this is a way around, etc etc... but that's what I need to do now...
ERROR:
[nodemon] app crashed - waiting for file changes before starting...
PACKAGE.json
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js",
"server": "nodemon app --ignore './client/'",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"build": "concurrently \"npm run server\" \"npm run client\""
},
starting using node server.
This occurred because the process was exited in a non-graceful way.
If you want auto-restart after crashing, that's not the purpose of nodemon.
I would recommend pm2
You could try using forever as advised in the nodemon FAQ.
forever -c "nodemon --exitcrash" app.js
This way if the script crashes, forever restarts the script, and if there are file changes, nodemon restarts your script.

How to do the setup for deploying Full-stack (Monggose, Express, Reactjs, Nodejs) website on Netlify

I have a website that deployed to Herokuapp. But unfortunately, the herokuapp had a problem to upload an image to a local folder so I tried to deploy my website to another site that is Netlify.
Here comes the problem. I only knew the build setup just for deploying to herokuapp, so this is my setup :
My Folder structure :
/client <-- "this is my create-react-app folder"
/config
/models
/routes
/validation
package.json
server.js <-- "my server"
package.json
/* some settings */
"scripts": {
"client-install": "npm install --prefix client",
"start": "node server.js",
"server": "nodemon server.js",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
},
/* some settings */
I don't know how to run the "heroku-postbuild" setting on Netlify to make it work. How can I accomplish this?
Thank you very much for your help!

Using nodemon and --inspect with serverless

I am writing a lambda service and hate having to stop and start the server after every change.
I do have this running together with chrome --inspect working correctly:
"start": "node --inspect-brk $(which serverless) invoke local -f getGoldenDeomondotcom"
I then used:
"start": "nodemon --exec \"node --inspect-brk $(which serverless) invoke local -f getGoldenDeomondotcom\""
to allow me to use nodemon with --inspect, however the messages don't pipe through to chrome.
Any ideas how I could use them together?
Make sure you use js or replace js in the code below with your language ext e.g py,ts
in your package.json
"scripts": {
"start:dev": "nodemon -e js --exec \"sls offline\""
},
From github ... (https://github.com/akupila)
nodemon --exec "serverless serve start"
I'm using this in package.json during dev:
"scripts": {
"start": "nodemon --exec \"serverless serve start\""
}
This allows me to just run npm start. Whenever any file in the project changes nodemon will restart serve.
I'm using serverless-offline and serverless-dynamodb-local, I just added
"start": "nodemon --exec \"sls offline start\"" to scripts

How can I run multiple NPM commands with a single NPM Command on Windows

I am setting a package.json file that will start Nodemon, run my watch css command and run browser sync all with the "npm start" command.
This works on my Mac computer at work but does not work on my Windows computer at home.
On my Mac, it will listen for any changes to server and SCSS files and also run browser sync.
On Windows it only runs Nodemon and just waits for any server changes. It looks like it ignores my other two commands.
Do I need to do something different for Windows? Ideally I would like the code to work universally on both platforms.
Nodemon seems to be the problem here because watch-css css and browsersync work but anything after nodemon does not work.
"scripts": {
"build-css": "node-sass --output-style compressed --source-map true -o public/css scss",
"watch-css": "nodemon -e scss -x \"npm run build-css\"",
"build-js": "browserify js/app.js -o public/js/app.js",
"browser-sync": "browser-sync start --port 4000 --proxy 'localhost:3000' --files 'views/*' 'public/**/*' --no-notify",
"start": "nodemon ./bin/www & npm run watch-css & npm run browser-sync"
},
Here's what I use: npm-run-all(this is cross-platform). They allow you to run your processes/commands parallelly and sequentially (-p or -s).
"scripts": {
"build-css": "node-sass-chokidar src/ -o src/ --importer=node_modules/node-sass-tilde-importer",
"watch-css": "npm run build-css && node-sass-chokidar src/ -o src/ --watch --recursive",
"start-js": "react-scripts start",
"start": "npm-run-all -p watch-css start-js",
// ... and much more
}
This is working fine for me in both windows and mac. Try it, hope this is helpful.

Npm scripts always gives an error as "is not recognized as an internal or external command"

I have a lerna repo. There is devDependency to concurrently package from my root package.json. When I type "lerna bootstrap" to command line, it works properly and install all root and subPackages` dependencies to root node_modules folder. But when i type "npm start" it says: 'concurrently' is not recognized as an internal or external command. When i check node_modules/concurrently folder it exists without problem.
My start script is concurrently --kill-others "npm run start-client" "npm run start-server".
This situation same with webpack-dev-server. How can i fix this problem except reinstalling everything.
package.json:
{
"name": "x-workspace",
"private": true,
"workspaces": [
"packages/*"
],
"devDependencies": {
"concurrently": "3.5.0",
"lerna": "^2.11.0"
},
"scripts": {
"start": "concurrently --kill-others \"npm run start-client\" \"npm run start-server\"",
"build": "webpack --hot",
"start-client": "npm --prefix ./packages/client-app start",
"start-server": "cd ./packages/server-app && dotnet run",
"clean": "rimraf node_modules package-lock.json ./packages/client-app/package-lock.json"
}
}
I found problem. There is no .bin folder in root node_modules folder. This is result of updating yarn to 1.8.0. When i return back to yarn 1.6.0, it works perfectly.
Thanks to David R. and other users.
I believe you don't have the concurrently package installed globally, To confirm try executing the below command and check if it returns anything,
npm list -g concurrently
If you've received an --(empty) response, then you'll have to install it globally.
npm install -g concurrently
Hope this helps!.

Categories