Can't run two scripts simultaneously in npm - npm

I'm trying to run two scripts in my fullstack app from root directory. Root directory has following structure:
./client
./server
./package.json (which is supposed to run both client and server). Client and server has their own package.json files where there is given scripts to run each.
In my root package.json I have following command:
"scripts": {
"server":"npm run dev --prefix server",
"client": "npm start --prefix client",
"watch": "npm run server & npm run client"
But only server is running. Can't run the client with this command

I just solved the problem. The reason was running two scripts simultaneously with ampersand (&) does not work in windows shell. So I had to change my default shell to bash shell with npm config set script-shell bash

Related

Running "npm run build" with specific env file

Whenever I run "npm run build" command, my vue project automatically use ".env.production" file(which is one of my .env files). I would like to build my project by specifying env files for example
npm run build .env.production (to deploy on production server)
npm run build .env.development (to deploy on development server)
Is there any way I can specify environment variables when running "npm run build"????
You can achieve this by edit package.json file and add the below run script
"build-production": "vue-cli-service build --mode production --dest ./dist/production",
This will take the environment variables from a file called .env.production if not found will search on file called .env
And will export the build in a dir called dist/production and you can change this from --dest part
Then you should run
npm run build-production
This will will run for production and you can make a second scrip and change to development to read from .env.development
Something like
"build-development": "vue-cli-service build --mode development --dest ./dist/development",

npm run server: Missing script

I'm trying to install ng-toolkit/universal and there are terminal 3 commands to set it up. I'm having trouble running the third command (npm run server). The error it gives me says:
Missing script: "server". To see a list of scripts, run: npm run
So I open my package.json and look under the 'scripts'. There is no 'server' entry. How do I know what this library is supposed to run under this command?
Under ng-toolkit/application/package.json "server": "node local.js" link

Run Jhipster-registry locally without browser sync

I'm trying to build a micro-services applications with JHipster. I'm following this tutorial.
I've successfully run jhipster-registry locally (I've cloned it, then run the commands ./mvnw and yarn start to be able to see the applications registered). Without this yarn start I can't see anything on my browser.
But I want to run my gateway application with the browser sync and I can't because it's focused on jhipster-registry.
I've a backend micro-service on port 8081.
My gateway is configured on port 8080, ./mvnw run successfully and I can see my application on localhost:8080. But I would like to have the hot reload when I run my npm start command on my gateway. I've configured my package.json to run on the port 9061 :
"webpack:dev": "npm run webpack-dev-server -- --config webpack/webpack.dev.js --inline --hot --port=9061 --watch-content-base --env.stats=minimal",
"webpack:dev-verbose": "npm run webpack-dev-server -- --config webpack/webpack.dev.js --inline --hot --port=9061 --watch-content-base --profile --progress --env.stats=normal",
When I run npm start it says I can see my app on localhost:9001, but I'm on the jhipster-registry...
Does someone can help me ?
Thanks to Gael Marziou, I've build the package like if I was in production with the commands :
./mvnw -Pprod package
And then :
java -jar target/jhipster-registry*.war
I've had to up the memory allocated for the build in the package.json file :
"webpack-dev-server": "node --max_old_space_size=6144 node_modules/webpack-dev-server/bin/webpack-dev-server.js",
"webpack": "node --max_old_space_size=6144 node_modules/webpack/bin/webpack.js",
because I had this error :

Serve SPA before running tests on cypress js

With Cypress I can test my dev subdomain easily. I have an angular/react application where when I make a dist (including index.html), I want to run Cypress tests against the built files.
Unfortunately, I have no idea how to serve a dist folder, (like serve package of npm) before starting Cypress tests.
I know that I can serve the index.html on another terminal tab, but this is not going to happen on CircleCi (my CI).
Is there anyway that Cypress can replace the localhost and serve static files before starting the actual tests?
I used browser-sync to launch a server that distribute my static files.
You need to install 3 packages: cypress (obviously), browser-sync to launch a server, and npm-run-all to launch a server and cypress consecutively.
npm install --save-dev cypress
npm install --save-dev browser-sync
npm install --save-dev npm-run-all
Here is an example of the npm scripts configuration that you will need to add in your package.json. Don't forget to customize the <port> (ex: 4000) and <folder> that contains the path to your SPA (ex: public).
{
"scripts": {
"cypress": "cypress run",
"server": "browser-sync start --port <port> --server <folder> --no-open",
"test": "run-p -r server cypress"
}
}
Now you have to write your first Hello world test:
describe('My App', function() {
it('is up', function() {
cy.visit('http://localhost:4000');
cy.contains('Hello world!');
});
});
That's it! We can launch our test:
npm test
I did the following:
I installed
npm i serve
and added
serve: "serve -s <build-folder>"
to my package.json. And then in your e.g. travis.yml you add
- npm run serve &
- npm test
The & at the end of your command will make it run in the backend and thus the test can run right after it. Since serve is pretty fast serving the static files there is no need for the npm test to wait either AND you do not have to worry about stopping the npm run serve afterwards since most CI environments are cleaning up background processes automatically after your tests finished.
Most of the information above can also be found here.

How to start http-server locally

I cloned angular seed which is using node http-server and it is working perfectly using following configuration.
Command : npm start (from root of project)
Following configuration in package.json file:
"start": "http-server -a localhost -p 8000 -c-1",
Link to file
However I'm unable to start this server directly. eg: from root of the project, none of these commands work:
> angular-seed npm http-server
> angular-seed node http-server
> angular-seed http-server
Shouldn't this(http-server) be available here(root, where it got installed from)? Could someone please explain me how it is working and how I can use it directly from root of the project.
I'm sure it will work fine if I install it globally but I'm not interested in that.
When you're running npm install in the project's root, it installs all of the npm dependencies into the project's node_modules directory.
If you take a look at the project's node_modules directory, you should see a directory called http-server, which holds the http-server package, and a .bin folder, which holds the executable binaries from the installed dependencies. The .bin directory should have the http-server binary (or a link to it).
So in your case, you should be able to start the http-server by running the following from your project's root directory (instead of npm start):
./node_modules/.bin/http-server -a localhost -p 8000 -c-1
This should have the same effect as running npm start.
If you're running a Bash shell, you can simplify this by adding the ./node_modules/.bin folder to your $PATH environment variable:
export PATH=./node_modules/.bin:$PATH
This will put this folder on your path, and you should be able to simply run
http-server -a localhost -p 8000 -c-1
To start server locally paste the below code in package.json and run npm start
in command line.
"scripts": {
"start": "http-server -c-1 -p 8081"
},