Nodemon resarts nodes server when writing a json file - javascript

My node server restarts every time when I write a json file using fs.writeFileSync().
How can I configure nodemon to ignore all json files in my project?
I tried adding nodemon.json file in root of my folder
{
"ignore": ["*.json"]
}
I tried also adding following code in package.json
..
"nodemonConfig": {
"ignore": [
"*.json"
]
}
Also tried to specify in nodemonConfig to ignore whole folder where I have json files "src/config/"

Related

Vue "npm run build" Ignores vue.config.js File

I have a Webpack-templated Vue project, initiated through vue-cli.
I have created a simple 'vue.config.js' file stored in the root folder (where package.json is at) containing the following:
// vue.config.js
module.exports = {
productionSourceMap: false
}
Though when building the project using "npm run build" it ignores it.
I have tried different configurations to check if the problem is with the file or the setting, and the problem is with the file.
I am using webpack#3.12.0, vue#2.6.11, #vue/cli 4.2.3 and npm#6.9.0.
Make sure your build confiuration (in your case the webpack build configs) include your file.
Generally, you will have a source folder (often src) and the builder will build all the files in that dir only. Then you have your destination directory (often dist or build) where your build files will be stored.
Two solutions:
add your conf file to the build source.
move your vue.conf.js file into your source directory
For some reason, I did not manage to get vue.config.js to work.
Alternatively, I edited my webpack config, which as my build files mentioned was located at /config/index.js
Then, I proceeded to pass my build configurations to the build parameter which already appears on the file.
build: {
...
}
And it worked. I assume it may be because I used npm run dev instead of the vue-service-cli, so webpack did not go through the vue.config.js file.

How do I get nodemon to watch dotenv-flow files?

dotenv-flow files can have names like: .env, .env.development, .env.development.local, ...
see: https://www.npmjs.com/package/dotenv-flow
I would like my node server to restart as soon as I update one of those files. However, adding a custom config, I am able to restart on a change in the .env file only.
"nodemonConfig": {
"watch": [".env"]
}
How could I watch files prefixed with .env ?
When overriding nodemon's watch list you need to provide a full match list. For example, to watch js files in the app directory, .env, and files prefixed with .env e.g. .env.development, you can use the following:
nodemon.json
{
"watch": ["app/*.js", ".env", ".env.*"]
}
The same concept works for dotenv-flow
dotenv-flow
"nodemonConfig": {
"watch": ["app/*.js", ".env", ".env.*"]
}
You'll likely need to modify the watch list a bit more to suit your needs. All in all, that's the gist.

How to create an express api executable

I have created a fully functioning fairly basic javaScript Node.js Express API application that I want to run as an executable in a windows environment. I am wanting to do this so I can give clients the ability to run my API on premise without exposing my source code to them.
Currently I have been using the pkg npm package which allows me to package my node.js application into an executable that will contain everything needed to run the app including node and my bundled source code.
My executable runs but my POST route is breaking with the following error:
"name": "RequestError",
"message": "Error: form-data: File or directory 'C:\\**\\myapp-api\\uploads\\1553103249524_test.wav' was not included into executable at compilation stage. Please recompile adding it as asset or script.",
"cause": {
"errno": -4058,
"code": "ENOENT",
"path": "C:\\snapshot\\myapp-api\\uploads\\test.wav",
"pkg": true
},
"error": {
"errno": -4058,
"code": "ENOENT",
"path": "C:\\snapshot\\myapp-api\\uploads\\1553103249524_test.wav",
"pkg": true
},
My POST allows clients to upload a file in a multipart form using multer.js to another external API that will return some metadata. pkg.js doesn't appear to have the means to discover files that are included after the bundling of the executable.
Is there anything I can do in my configuration for my uploaded files to be included? Is there some other utility or process that others use for creating an executable of their node.js express APIs that would better handle the issue I am having?
Any guidance would really be great.
Try adding your files under "assets" in the package.json file.
The config paragraph on the pkg website https://www.npmjs.com/package/pkg#config states:
So you must specify the files - scripts and assets - manually in pkg property of your package.json file.
"pkg": {
"scripts": "build/**/*.js",
"assets": "views/**/*"
}
You may also specify arrays of globs:
"assets": [ "assets/**/*", "images/**/*" ]
Just be sure to call pkg package.json or pkg . to make use of scripts and assets entries.
You are probably using something like this in your script (I am guessing since you didnt provide this part of the code)
app.use(express.static(__dirname+'/uploads'));
res.sendFile(path.join(__dirname+'/uploads'));
__dirname will be wrong when you pack your .exe get rid of it everywhere and replace it with ./
app.use(express.static('./uploads'));
res.sendFile(path.join('./uploads'));
Something like that. It worked for me.
Good luck!

Nuxt js restart server on api folder changes

In my nuxt js application, I am trying to restart the server files which is in the api folder when a file changes.
In order to that, I've added the following to nuxt.config.js
build: {
watch: ["~/api/index.js"]
}
When I make the changes on the files in API folder server doesn't restarted automatically
I've tried this thread Watch and reload api folder in Vue Nuxt looks similar to my problem but it doesn't worked for me
As suggested here
Watch and reload api folder in Vue Nuxt
just adding
watch: ['api'],
to nuxt.config.js, at the root level, worked for me. Not under build, as you had it.
EDIT
Bizarrely, although I now see the server (and client, for some reason) being started in the console... the new code is not taken! So, that's fairly useless.
The only way to get the code changes is still to ctrl-C and restart from zero.
In my application, I use nodemon.json config
{
"verbose": true,
"ignore": ["node_modules", "dist"],
"watch": [
"app.js"
],
"ext": "js json"
}

NPM script to remove a string from file after processing?

In the package.json in my Angular 6 project, we have a bunch of node scripts to run and build our project.
I created a new script to process a scss file into an output directory:
"unbranded": "node-sass -x --output-style expanded ./client/src/app/demo/unbrandeddemo/unbranded.scss > ./dspackage/dist/css/unbranded.css",
This creates a css file at ./dspackage/dist/css/unbranded.css
Now I need to find and remove a string in this file after it's made. So I created tried installing the replace-in-file npm package and am trying
"postunbranded": "replace-in-file from to ./dspackage/dist/css/unbranded.css, ./dspackage/dist/css/unbranded.css --configFile=replace-config.js"
Where the replace-config-js is a file in the same directory as the package.json,
const options = {
from: /::ng-deep/g,
to: ''
};
I've tried various versions of this setup, but get the error:
Error: must provide pattern

Categories

Resources