I ran into a proxy problem in my package.json file.
"dev": "set PROXY = true && node server.js",
"dev-saas": "set PROXY = true && node server.js",
On Windows, this code does not start the program and gives an error
'PROXY' is not recognized as an internal or external command,
operable program or batch file.
After doing a little google search, I changed the code to this
"dev": "set PROXY = true && node server.js",
"dev-saas": "set PROXY = true && node server.js",
and wrote a little below:
"proxy": {
"target": "http: // localhost: 3001"
},
After that, the code works, but I don't think it's correct, because it gives an error:
Error: [HPM] Missing "target" option. Example: {target: "http://www.example.org/%22%7D
Related
I just installed json-server and ran it, then I got an error.
db.json
{
"user": {
"id": 0,
"name": "John"
}
}
a part of package.json
"scripts": {
"json-server": "json-server --watch db.json -port 5000"
},
I ran npm run json-server and I got
> myproject#0.1.0 json-server
> json-server --watch db.json -port 5000
\{^_^}/ hi!
Loading db.json
Loading true
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received type boolean (true)
at Object.openSync (node:fs:591:10)
at Object.readFileSync (node:fs:467:35)
at /Users/admin/project/myproject/node_modules/json-server/lib/cli/run.js:118:32 {
code: 'ERR_INVALID_ARG_TYPE'
}
There is an issue but these solutions didn't work for me. Some people say use the latest react-scripts, so I use the latest one.
Environment
macOS 12.5
TypeScript 4.8.4
React 18.2.0
react-scripts 5.0.1
json-server 0.17.0
Thank you to read, can anyone solve it?
I had the same issue. Starting json-server with sudo privileges made it run
How can I write a test that npm scripts run successfully?
I have npm scripts in package.json as follows.
"scripts": {
"start": "node server.js",
"dev": "webpack serve --mode development",
"lint": "eslint src",
...
I'd like to test these npm scripts launch successfully.
For example, how do I test the command npm run dev (webpack serve) launches successfully?
You test them like you test a computer process - independent of JavaScript. You treat the fact webpack/eslint are JavaScript programs as an implementation detail.
Basically - they should only be tested in really really big projects and have a few tests.
A test can look something like:
const util = require('util');
const { exec } = util.promisify(require('child_process').exec);
describe('your run scripts', () => {
it('starts a dev server', () => {
// create a way to stop the server
const ac = new AbortController();
// start the dev server
const devServerPromise = exec('npm run dev', { signal: ac.signal });
// validate the server launched (retry comes from any promise retry package, fetch can be unidici or axios just the same)
// localhost:4200 is an example for where the dev server is running
await retry(() => fetch('http://localhost:4200/'));
ac.abort(); // close the dev erver
});
});
Note that like I started with there is very little return on investment on writing these sort of tests if your project isn't thousands of developers since the issues with stuff like npm run dev are noticed very very quickly by developers and the cost of having another call-site for them that needs to be aware of certain implementation details is high.
I have created the vite project it is working perfectly fine in the localhost. But when my project was deployed in AWS EC2 instance, I am getting following error message :
Websocket connection to 'wss://www.domain.com/3000' failed:
[vite] server connnection lost. polling for restart...
pacakge.json :
{
"name": "screen-recording-demo",
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"serve": "vite preview"
},
"devDependencies": {
"vite": "^2.0.5"
},
"dependencies": {
"firebase": "^8.2.10"
}
}
I have used firebase dependencies in my project in locally everything is working fine. I have checked the vite doumentation, but not getting what needs to be added or I am missing in the production.
based on my experience this a day ago, i need to open the port used
in Nuxt 3 it's 24678, so i must execute these
ufw allow 24678/tcp
I am working on a cypress project. I have set up a pipeline in GitLab.
My application only works over private network connected via Open VPN.
Can some one guide me how to add that in .gitlab-ci.yml file ???
My .gitlab-ci.yml is :
image: cypress/base:10
stages:
- test
test:
stage: test
script:
- npm install
- npm run test
and my package.json is as follows:
{
"name": "cypresspackage",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"clean:reports": "rm -R -f cypress/reports && mkdir cypress/reports && mkdir cypress/reports/mochareports",
"pretest": "npm run clean:reports",
"scripts": "cypress run --spec cypress/integration/dummy.feature",
"combine-reports": "mochawesome-merge ./cypress/reports/mocha/*.json > cypress/reports/mochareports/report.json",
"generate-report": "marge cypress/reports/mochareports/report.json -f report -o cypress/reports/mochareports",
"report:copyScreenshots": "cp -r cypress/screenshots cypress/reports/mochareports/assets",
"posttest": "npm run report:copyScreenshots && npm run combine-reports && npm run generate-report",
"test": "npm run scripts || npm run posttest"
},
"author": "",
"license": "ISC",
"devDependencies": {
"cypress": "^6.3.0",
"cypress-audit": "^0.3.0",
"cypress-cucumber-preprocessor": "^4.0.1",
"cypress-multi-reporters": "^1.4.0",
"cypress-xpath": "^1.6.2",
"mocha": "^8.2.1",
"mochawesome": "^6.2.1",
"mochawesome-merge": "^4.2.0",
"mochawesome-report-generator": "^5.1.0"
},
"dependencies": {
"lambdatest-cypress-cli": "^1.0.1"
},
"cypress-cucumber-preprocessor": {
"nonGlobalStepDefinitions": true
}
}
I guess gitlab provides the runner at run time
I guess you are using GitLab's SaaS. This means your VPN would be opened in a non-private environment. For example, some GitLab admins should have access to your VPN connection and, depending on how GitLab is configured in their backyard, some other GitLab users may have access to your private network. I'd avoid that. If you insist on that, you'd better use your project's Secrets feature to save your OpenVPN client authentication, so it remains private.
Is there a option where I can choose the runner?
Sure. You can register a runner running on your own servers (or even at home on-demand). It depends on where and how this runner is being used (Docker? Kubernetes? Debian? etc). Take a look into Registering a GitLab Runner. You'll need to generate a token from your project's configuration and then install the runner using that token.
GitLab CI
Once you have your own runner installed and configured (ensuring it runs when needed), you'll need to configure your VPN start/stop in the pipeline. Here, I copy a piece of code found on GitLab's forum:
before_script:
##
## VPN
## Inspiration from: https://torguard.net/knowledgebase.php?action=displayarticle&id=138
## And http://forum.gitlab.com/t/connect-vpn-during-ci-cd/7585
## Content from Variables to files: https://stackoverflow.com/a/49418265/4396362
## Waiting for opnevpn connect would be better than sleeping, the closest would be https://askubuntu.com/questions/28733/how-do-i-run-a-script-after-openvpn-has-connected-successfully
## Maybe this would work https://unix.stackexchange.com/questions/403202/create-bash-script-to-wait-and-then-run
##
- which openvpn || (apt-get update -y -qq && apt-get install -y -qq openvpn) # Install openvpn if not available.
- cat <<< $CLIENT_OVPN > /etc/openvpn/client.conf # Move vpn config from gitlab variable to config file.
- cat <<< $VPN_U > /etc/openvpn/pass.txt # Move vpn user from gitlab variable to pass file.
- cat <<< $VPN_P >> /etc/openvpn/pass.txt # Move vpn password from gitlab variable to pass file.
- cat <<< "auth-user-pass /etc/openvpn/pass.txt" >> /etc/openvpn/client.conf # Tell vpn config to use password file.
- cat <<< "log /etc/openvpn/client.log" >> /etc/openvpn/client.conf # Tell vpn config to use log file.
- openvpn --config /etc/openvpn/client.conf --daemon # Start openvpn with config as a deamon.
- sleep 30s # Wait for some time so the vpn can connect before doing anything else.
- cat /etc/openvpn/client.log # Print the vpn log.
- ping -c 1 <IP> # Ping the server I want to deploy to. If not available this stops the deployment process.
After this, you can add an after_script section to stop the OpenVPN daemon, or using a special closing job which includes a when: always, to ensure the VPN connection is closed even if the build failed.
You can also try other solutions, depending on your environment.
Trying to run multiple separate servers in parallel from package.json. This method only runs server1.js, but ignores server2.js
Package.json
{
"name": "demo",
"version": "1.0.0",
"description": "demo",
"main": "server1.js",
"dependencies": {
"express": "^4.14.0",
"socket.io": "^1.5.1"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server1.js && node server2.js",
}
}
P.S -- code will be used in AWS
In the shell, && is a command that executes the next command after the previous command is executed, and if the state is true.
If you want multiple servers to run in parallel at the same time, use the background process commands, & or nohub.
node server1.js & node server2.js &
and now, your application runs in the background, and the process information can be obtained with the command below.
If you want to stop this, get pid information with netstat command
You must delete it with the command kill -9 <your_procees_id>.
netstat -vanp --tcp | grep <your_server_port>
kill -i <your_process_id>
Alternatively, there may be a monitoring module such as pm2.
https://www.npmjs.com/package/pm2