pm2 watching inside folders, having issues - javascript

I'm trying to have pm2 watch everything in events, commands, data, index.js, and config.js.
pm2 --name druggy --watch
events,commands,data,index.js,config.js/index.js start node -- index.js
I used this and whenever I try to change a file in one of the folders, when I save my bot it doesn't restart. However it does restart if I change the index.js. How can I make it restart when I change anything inside those folders and the two files?

Do not give --watch any parameters. You do not pass them in through the command line, anyways. Change your command to the following:
pm2 start index.js --name druggy --watch
If you do want to specify which paths to watch, then follow the documentation located here.

Related

nodemon Internal watch failed: watch /Users/admin/Library/Application Support/Code/1.26.1-shared.sock Unknown system error -102

I installed nodemon in my Macbook Pro using sudo npm install nodemon -g command just today.
I am trying to run my Node JS code using the below command.
nodemon /Users/admin/nodejs/my-express-server/src/index.js
The script starts fine however immediately terminates with the below error.
[nodemon] Internal watch failed: watch /Users/admin/Library/Application Support/Code/1.26.1-shared.sock Unknown system error -102
I see few similar instances of questions already in Stack Overflow, however the error code/scenario is different. Also, I tried the answers from those similar questions and it didn't help.
So from the comments I got to know that you are running nodemon from your user directory or home directory. which is ~ or /Users/admin in your case.
Now nodemon watches EVERY directory and subdirectory for file changes. You can see that by watching dir(s): *.*
So when you are running:
nodemon /Users/admin/nodejs/my-express-server/src/index.js
You are running the index.js file but you are telling nodemon to watch every directory and file under the current working directory(which is /Users/admin in your case).
So, many Mac installations, application support files, basically every file you ever create by default goes to any directory under the home directory.
Now nodemon checks every file for change and the nodemon coudldn't put watch on vscode shared.lock file probably because of permission issue or the file is being opened by vscode itself.
Long story short(not really), go to the /Users/admin/nodejs/my-express-server/ folder and run nodemon from there.
cd /Users/admin/nodejs/my-express-server
nodemon src/index.js

webpack custom command on watched files change

I'd like to be able to run a custom command when webpack detects that my files have changed. The command is to run a middleman build command that is based on rails, and not a simple js build/include.
How would I go about this?
You can use any application that is built on top of fsnotify library. From ruby world you can use guard or nodemon from Javascript world.
You'd want to watch your generated files.
Whenever any of the two files changes, it will execute the command.
nodemon --watch webpack.config.js --watch webpack.parts.js --exec \"webpack-dev-server --env development\"

What is difference between node and nodemon?

in my package.json I am using
"scripts": {
"start": "node app.js"
},
but if I use nodemon replace with node app.js like
"scripts": {
"start": "nodemon app.js"
},
then what will happen? Because when I got any error at server side, other API also close working. So I think it happen because I use node app.js if I use nodemon app.js than server will restart or not.
When you develop a node app and you make some changes, to see them in effect you have to restart the server.
When you launch your node.js application with Nodemon it will monitor for any changes and automatically restart the server, improving your productivity.
Nodemon is a utility that will monitor for any changes in your source and automatically restart your server. Perfect for development. Install it using npm.
npm install -g nodemon
How to use nodemon?
nodemon "filename" ignore the quotation and place name of the server file.
Nodemon:
monitors for any changes in your Node.js application
automatically restarts the server,
saving time and tedious work.
it's one way to make your development efficient with Opn:
Opn is a dependency that opens web browser links, files, and executables. We will be using Opn to automatically open a web browser to our local host every time our server restarts.Install with npm
npm install opn.
How to use node?
node "filename" ignore the quotation and place the filename (ex app.js ,server.js)
node:
no automatic restart the server every time you do the tedious work
no monitors for any change
nodemon is like a live-server for your node application. any changes made in your node application will get reflected as server will restart again.
as stated here :
nodemon will watch the files in the directory in which nodemon was
started, and if any files change, nodemon will automatically restart
your node application.
nodemon is a tool that helps develop node.js based applications by automatically restarting the node application when file changes in the directory are detected.
To use nodemon, replace the word node on the command line when executing your script.
In terminal,instead of typing node app.js,you can type: npm start
In package.json file,you can change it to:
"scripts": {
"start": "nodemon app.js"
},
In short,it is like a live server for node js, like we have in HTML & CSS.
When you are using node you have to restart on your own to see the changes you made But nodemon watches the particular path for any changes.If you make any changes in your file, nodemon will restart it for you.
when we install node, we will get automatically node and npm global variable.
for using nodemon you need to install it
npm install -g nodemon
we can access files with node as well but each time when we do changes we need to stop server and restart it.
node "filename" // provide filename
but if we accessing file with nodemon you no need to stop server and restart it only one line of command will save restart server time
nodemon "filename" // provide filename
this one line helps you saving lot of development time and test your sample javascript code
Nodemon stands for Node Monitor.
When you run a server using the command node index.js, after every change in your code you have to again run the node index.js command and reload the page to see the changes. Nodemon solves this problem for you. It auto-updates the server for you.

How to automatically reload Node.js project when using pm2

I am currently programming Node.js with Express.js, and every time I change a line of code in the file router or app, I need to type the command:
pm2 reload id_project.
How do I make pm2 auto-reload the project when a file is changed?
You need to start your pm2 project with the --watch option:
pm2 start <script|name|id> --watch
Where <script|name|id> refers to:
script the path to the script you want to let pm2 handle
name the name of the configuration in the "ecosystem" file
id refers to an already running application using pm2, which can be obtained using pm2 list (note that this would actually require a restart instead of start, so it's probably the least desirable of the options)
You could also specify which files/directories to ignore:
pm2 start <script> --watch --ignore-watch "node_modules"
Watch & Restart
Or create an "ecosystem" json file describing how you want pm2 to treat your project:
{
"name": "project_name",
"script": "index.js",
"watch": true,
"ignore_watch": ["node_modules"]
}
JSON options
PM2 comes with a handy development tool that allow you to start an application and restart it on file change:
# Start your application in development mode
# it print the logs and restart on file change too
# Two way of running your application :
pm2-dev start my-app.js
# or
pm2-dev my-app.js
By default, pm2 doesn’t automatically refresh our server every time we change files.
You need to start your pm2 project with the --watch cli argument in order to tell pm2 to refresh when files have changed:
pm2 start id_project --watch
check out the docs for more details, or #rogier-spieker answer which is more detailed.
pm2 is a Node process manager that has lots of bells and whistles. you can run the below command to automatically restarting the node application when file changes in the directory are detected.
pm2 start index.js --watch
Note that because pm2 runs things in the background, you can’t just ctrl+c your way out of a running pm2 process. You have to stop it by passing the ID or the name.
pm2 stop 0
pm2 stop index
other two options are below
npx supervisor index.js
nodemon index.js

React - jsx --watch does nothing after first conversion

I can't use in browser JSXTransformer.js even for development, because i am using require.js for loading modules.
When i run jsx --watch src/ build/, actually just one jsx->js conversion is performed against files in src directory, but subsequently, if i change any file in src directory, nothing happened, no translation jsx->js (like if jsx --watch didn't noticed any changes).
Same happened to me.
Try this command line:
jsx --watch -x jsx src/ build/
I had the same problem, but this helped:
jsx --watch ./scr ./build
Actually it happens when you are trying to start the command from wrong folder or set the wrong path to folder from which you want to build (e.g. "src/"). Write path depends on you directory's structure. Best way to find out write path is to print the command "jsx --watch " and then use Tab to get path to directory you need or just make sure the current folder in terminal contains build/ and src/ folders.
I'm having the same issue, and maybe it's because I don't really understand how "--watch" is supposed to work. What I initial did was this: open terminal, punch in "watch" command (e.g. "jsx --watch /src /build). As soon as I did that, the terminal spit back something like "helloworld.js was built". All good.
Then I closed the terminal window and nothing worked after that.
Then I re-opened the terminal, re-typed the command, and the watch command worked.
Then I closed the terminal, and it stopped working.
I'm sensing a pattern here. Is the JSX watch command only active while the containing terminal window is open? I assumed "watch" was a "set it once and forget it" command, but it sounds like it's more ephemeral than that?
You have this issue probably bacause of the suffix of the files is jsx and not js the jsx command not recognize .jsx files.
You can do as user2038099 said:
jsx --watch -x jsx src/ build/
-x, --extension File extension to assume when resolving module identifiers
or you can change the suffix of the files in the src folder to .js.
https://github.com/facebook/react/issues/4269
I had this problem running Ubuntu 14.04. The jsx command would not give any feedback regardless what arguments I passed it. I eventually ended up uninstalling node entirely and installed using the instructions for Ubuntu at https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
I was previously on nodejs v0.10.28, but now that I'm on nodejs v0.12.7 everything is working fine.

Categories

Resources