I have a script called modifyFile.js that I would like to run right after the vue development server starts. Currently, I have the dev script as "vite && npm run modifyFile" However, the modifyFile script never runs since vite spins up a server and the server is still running.
How do I go about fixing it? I want to run both actions in one command - npm run dev.
// package.json
{
"name": "test",
"version": "0.0.0",
"scripts": {
"dev": "vite && npm run modifyFile",
"modifyFile": "node modifyFile.js",
"build": "vite build",
"preview": "vite preview --port 4173",
},
}
Related
I have a Next.js application and I want to connect it to a Node.js backend.
If i put the file server.js in the same folder of the Next.js application I can run the application through these scripts:
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "set NODE_ENV=production node server.js",
"lint": "next lint"
}
I want to put all the backend files in another folder (server.js too) , but in this case I can't run the application.
What I have to do? Thanks
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 deploy react (Create-React-App), Express.js and MySQL ?
I tried deploying on cPanel. do I have to change it to Production mode?
how do I access the API on Express.js? do I have to create a sub domain on Express.js?
because so far I only use the library which is concurrently and nodemon. and on React.js I added a proxy like this:
"proxy": "http: // localhost: 5000", where localhost: 5000 has a port from Express.js
Package.json script in server.js
"scripts": {
"client-install": "npm install --prefix client",
"start": "node server.js",
"server": "nodemon server.js",
"client": "npm start --prefix client",
"dev": "concurrently --kill-others \" npm run server\" \"npm run client\""
},
Package.json script in React
"proxy": "http://localhost:5000",
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
My App :
Client > folder react app > Package.json,Src
Node modules > npm from server
Server > Express config,Routes,Controller
.babelrc
server.js
package.json
Do you have terminal access on the cPanel? If yes, then
Start your node server (Using PS or Nodemon)
If your cPanel is using any kind of a server (nginx or Apache webserver for example), then configure the server file to redirect to localhost:5050 on *:80 and *:443
Configure your Express.js to serve on port 5050
And that's it.
I need to build My React NextJS Project on local to host it at Appache server, when I run command run build it did not generate build folder.
I R & D on it, everyone recommend ZEIT – Next.js build with Now but it build project on cloud but I need a build for my local appache server. So please help me out.
Here is an my of package.json:
......
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "next start"
},
......
After so many struggle, I found answer of my question I have to add following line in my package.json under scripts:
"scripts": {
......
"export": "npm run build && next export"
.....
},
Basically I my case, npm run build && next export was complete required command to build NextJS project. So after adding this into package.json you just need to run in terminal:
npm export
and it will generate complete build for nextjs project.
You have a package.json script called build that runs next build. The next build command by default builds the app for development, which doesn't create a production bundle.
In order to create the production bundle on your local machine, you need to specify that you're on production environment through NODE_ENV=production (this is done automatically in now and other deployment servers). Basically, your package.json would end up:
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "next start",
"prod:build": "NODE_ENV=production npm run build"
},
You can replace npm run build with next build directly if you prefer that.
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