I'm developing a discord bot for discord at the moment, and to run the bot, I have a few different files. I've run into some problems along the way that all ended up having the same fix, or at least the only fix that I could come up with. That fix would be, instead of running them in my main file (index.js), I could just run 3 separate batch files using nodemon (https://www.npmjs.com/package/nodemon). I currently have 3 batch files to do so. Those batch files look like this:
nodemon index.js
pause
This would be for the main file.
nodemon logs.js
pause
This would be for the file that logs messages.
nodemon welcome and goodbye.js
pause
And this would be for the welcome and goodbye logs.
The only issue is, is that it clutters up my desktop with 3 different prompts, making it confusing as to what does what. I was wondering if it'd be possible with nodemon (or any other npm like this) for me to run all 3 of those batch files in one single command prompt.
And of course I'm open to other npms, but if I'd have to use another one, please include a way for it to automatically restart the server when I save the file in it as well (if possible). Since that's the main reason I like nodemon. I'd also like to be able to use a command prompt/batch file rather than the Visual Studio Code terminal.
If you're wondering what I mean when I say, "...automatically restart the server when I save the file," . (https://imgur.com/a/rw2Qagp if it doesn't show, don't know how to format this stuff)
Whenever I save my code in Visual Studio it will restart and load the new code.
I'm still a little new to coding and stuff like that, so if my terminology is off I do apologize. If I did use a term incorrectly and you are confused/have a question about it, leave a comment and I will do my best too explain what I mean.
Thank you for taking time to read this.
You can use concurrently or parallel in order to make it cross platform
example with concurrently:
package.json
{
"scripts": {
"serve": "nodemon index.js",
"logs": "nodemon logs.js",
"start": "concurrently \"npm:serve\" \"npm:logs\""
},
"devDependencies": {
"concurrently": "^5.0.0",
}
}
Edit: you may want to take a look at the VSCode Compound tasks
Here's an example setup
Welcome :-)
I think you mean bash file (.sh) instead of batch file. So, in the terminal, you can && commands to chain them together.
For example, you could chain them together like this:
nodemon ./appOne/index.js && nodemon ./appTwo/index.js && nodemon welcome and goodbye.js
and they will all execute at one time. Additionally, you could make a bash file somewhere on your computer that did exactly what I typed above :-)
Now if you wanted them to go to the background and you wanted to forget about them, you could put them in the background with one ampersand... like so:
nodemon index.js &
and it would disappear and you'd have your console back. It would also print out a process ID (PID) of what that node process is under, so you can find it and kill it later (via kill -9 processid)
Related
I am very new to coding and following a tutorial at the moment (building a simple CRUD app). The issue is that once I run the command "nodemon app", I can no longer use any other commands. I can type it out but hitting enter does nothing. How do I use other commands without opening a new terminal?
click here for image
Ctrl+C will interrupt the running process in a terminal, in this case, killing nodemon.
That would allow you to run other commands, but will lose you your nodemon process.
Another option (that might be more suitable for VSCode) is to open a second terminal (Ctrl+Shift+`, or Ctrl+Shift+5 to open side-by-side). In the second terminal, you can then execute whatever other commands you want.
Alternatively, you can append the & character to a command to have it run in the background. This would allow you to run something like nodemon app & and then run other commands, but be aware that in this arrangement, the output of the commands will become interleaved - so if the node application is writing to the console and the other command also outputs information, they might become tricky to read.
My goal is to modify the Minio browser for front end appearance in house. I'd like to add features too but can't seem to get either to work and feel like I'm missing something about how go accesses npm or the browser.
I have made changes to the Minio web browser (javascript) and can see them when running with npm (in ./browser 'npm run release;npm run dev'), but when I try to run minio server built with the same git clone (changes is browser subdir) and browse to localhost:9000 I don't see any of the changes.
It would also be nice to run the browser with npm and connect to the running server "./minio server ~/data", but they don't seem to talk and I'm unclear on how they're connected.
This seems to be a simple case of all the things I tried and in the right order.
Correct order:
cd browser; npm run release
cd ..; make
./minio server ~/minio-data
It seems I'd tried all of these separately but not in the obvious order. I'm assuming npm makes the ui-assets.go which gets included by the make
I'd like to start a Nodejs debugger for my Hexo blog to understand how my theme works and possibly find a bug.
I needed 2 things to achieve this:
Install hexo-cli as a dev dependency rather than global. I used npm i hexo-cli --save-dev.
In package.json, under scripts, add a script called debug. I used this command: node --inspect=4300 ./node_modules/hexo-cli/bin/hexo server.
Then just use npm run debug and you're good to connect with a debugger to port 4300 (or whatever port you want to set in your command) and do line-to-line debugging etc.
One caveat is that with the --inspect setting, for some reason hexo is starting extremely slow (takes more than 2 minutes). I wonder what causes this.
Also, I haven't found a way to start hexo in a way that it generates pages dynamically. It would help with real time debugging.
I have a Discord bot that I'm writing a restart function for. I want to be able to run one command that will not only stop the script, but kill and restart it, so I can implement updates quickly. I've realized that the Discord API is not sufficient for this so I haven't added it to the tags. The simplest way I can think of is by using two scripts that call each other.
Every resource I've found references either a module (?) called PM2 or a programming language called VBScript. I do not want to mess around with a module that automatically reboots every single time I save, and I especially don't want to try learning a new language.
Here is my pseudocode showing what I'm aiming for:
[bot.js]
function reboot() {
runFile(`./reboot.js`)
}
[reboot.js]
kill (`./bot.js`)
runFile(`./bot.js`)
The result I'm hoping for is for bot.js to run reboot.js. Reboot.js will then quit bot.js and run it again. Then reboot.js will close. I don't care about any processes already running on bot.js.
Of course, if there are even simpler ways to do this, please let me know. I need as much simplicity as I can get.
PM2 is a process manager and would do the trick for you.
It's easily installed: npm install pm2 -g
Start your bot: pm2 start bot.js --name "Discord Bot"
Code-wise, you'll want to simply kill the process. PM2, being a process manager, will restart it for you.
I've figured it out. I used the child-process module built into node.js.
[bot.js]
var cp = require('child_process');
function reboot() {
var ls = cp.spawn('node', ['reboot.js']);
client.destroy()
}
[full contents of reboot.js]
var cp = require('child_process');
var ls = cp.spawn('node', ['bot.js']);
(posting all this for fellow noobs to use)
Edit: Note that after restarting, console outputs no longer work, as it's running from reboot.js rather than directly from the terminal.
I'm not familiar with Discord bots, but if you want to start, kill and restart processes programmatically in NodeJS then you want to look into the child_process module.
https://nodejs.org/api/child_process.html#child_process_child_process
I'm trying to learn React and the whole environment built around it. I do that by trying to construct my own dev-stack.
The problem I can't get across for a very long time is how to serve CSS/Images while not loosing a power of server rendering.
I've read a couple of tutorials and discovered webpack-isomorphic-tools
I've configured them and managed to get an images supported, sass (transformed to css) as well.
However, I came across an issue that my webpack-assets.json file is not generated, instead I see this output. ( I managed to get it generated on a 2nd run of npm start before this commit, but that was definitely not a way to go , but it showed that the plugin works when a file is present.)
$ npm start
> redux-universal-example#0.0.0 start /Users/janvorcak/learning2016
> node src/server/index.js
[webpack-isomorphic-tools] (waiting for the first Webpack build to finish)
[webpack-isomorphic-tools] (waiting for the first Webpack build to finish)
[webpack-isomorphic-tools] (waiting for the first Webpack build to finish)
[webpack-isomorphic-tools] (waiting for the first Webpack build to finish)
I understand the purpose of this file, but I can't really figure out why it's not generated at all.
Is there anything that I'm missing?
Here are the relevant files and a repository
https://github.com/jvorcak/universal-react-kit/tree/sass-loader
(sass-loader branch on my universal-react-kit repository)
configuration -
https://github.com/jvorcak/universal-react-kit/blob/sass-loader/webpack-isomorphic-tools-configuration.js
webpack.config.js -
https://github.com/jvorcak/universal-react-kit/blob/sass-loader/webpack.config.js
entry file when running a server https://github.com/jvorcak/universal-react-kit/blob/sass-loader/src/server/index.js
Could somebody please explain what is going on, I've read documentation, blogs, but I'm missing something here. Thank you.
The reason the assets file is not generated is because you have integrated webpack-dev-server into your server.js.
https://github.com/jvorcak/universal-react-kit/blob/master/src/server/server.js#L81
That's a wrong way to do it because in production you won't need webpack-dev-server and therefore its place is somewhere else.
In your case webpack-dev-server is meant to generate webpack-assets.json and this webpack-dev-server is being run after webpack-isomorphic-tools .server() method calls its callback, but it won't call its callback until it finds webpack-assets.json.
The answer is to run your webpack-dev-server in a separate process (you may want to refer to github.com/erikras/react-redux-universal-hot-example for an example of how to achieve that).
https://github.com/halt-hammerzeit/webpack-isomorphic-tools/issues/47
You may also like my very own boilerplate which can do all the fancy things
https://github.com/halt-hammerzeit/webapp