Run pre and post commands to npm test - javascript

I wanted to run pre and post commands while executing npm test.
As a pre command, i wanted to run my .exe which will need for testing and after the testing is completed and i wanted to kill the .exe.
I have add below code in my package.json tried to execute npm test command, it is executing batch file and my server.exe is running but my tests are paused.
Batch file contains the command start C:\server.exe
'test' : 'C:/test.bat && ng test'

Related

How to run npm run command in onComplete hook in wdio

In wdio test project, I want to generate and open allure report once test execution is completed and to do this I've added a command ("allure-report": "allure generate ui-tests/allure-results --clean && allure open") as a script in package.json file. To open the allure report post-execution, I need to run this command "npm run allure-report" manually, which successfully opens the report in the web browser. But instead of running this command manually every time post-execution, I want to add this command to be executed itself by putting it in the onComplete hook in the wdio.config.js file.
To do this I have added the following in onComplete hook which is not working:
onComplete: function(exitCode) { require('child_process').spawnSync('npm', ['run', 'allure-report'], {cwd: __dirname + '/package.json' }) }
Does anyone know how to make this command run itself in onComplete hook post test execution which open the allure report

How to run node.js application from script?

I am trying to run my node.js application from a script I have written:
echo "Starting node application"
sudo node /home/pi/PPBot/bot.js
exit 0
I run the script like this: sudo /etc/init.d/botscript
The output when running the script is:
Start node application
sudo: node: command not found
I have also tried replacing node by /home/pi/.nvm/versions/node/v.8.11.3/bin/node but this resulted in the same output.
I have already installed NodeJS through NVM. Simply using the command node bot.js works from the command line. However as can be seen above it does not work through the script.
if you want to run a simple node js file then use the command
-> node filename
ex.: node server.js
if you want to run a node js file with nodemon then use the command
-> nodemon filename
ex.: nodemon server.js

DroidEdit Termux integration

DroidEdit allows you to run commands if you have sl4a installed and the am command works wonderfully... I was wondering if there is a way to use am to launch an app with params .. specifically I want a command that will tell termux to run a command on a file that I specificy ... so far I found this snippet that launches the termux app .. now how do I get it to run node or webpack from npm as well?
am start --user 0 -n com.termux/com.termux.app.TermuxActivity

how to reload the nodejs app after making changes to the file?

i have a simple js file with http module to test Hello node for nodejs....
below is the http_test.js file
var http = require('http');
http.createServer(function(req, res) {
res.writeHead(200);
res.end('hello node');
}).listen(8080);
node http_test.js prints fine on the browser...now if i change my response line to say res.end('changed hello node to hello stoner');, i still get previous hello node on my page....
to get the changed line i got to end the current instance of node and then again run
node http_test.js
if i make any changes to js file should i restart over?
wouldnt just hitting refresh on my browser do it?
You need to stop and re run the server to see your latest update. To automate this, you can use nodemon, do npm i nodemon -g
And run nodemon http_test.js
Now, for every change you make tohttp_test.js the server will be restarted automatically
1) Install nodemon. To install, from your terminal run:
npm install -g nodemon
2) Now, go to terminal, where you have the program. And, run
nodemon http_test.js
Now, everytime when you make changes to your app, just save your changes and it will get reflected.
Details :-
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.
Just use nodemon instead of node to run your code, and now your process will automatically restart when your code changes.
Please refer :-
http://nodemon.io/
https://github.com/remy/nodemon
You have to restart your server, because the file had load to the memory .
Or you can use nodemon who auto restart your server when you change file.

how to determine if gulp watch is running

I run gulp on server in background running
gulp &
but sometimes it fail down. So mi question is: Is there some command for gulp to ask if is running. Something like
gulp status
Thanks
There is nothing special in gulp to limit running multiple processes or alert you to an already running gulp process.
Use regular Unix techniques to check if a process is running. Use a supervisor like supervisord or runit to automatically restart processes.
#the program pidof will set the variable $? to either
#1 or 0 in bash depending on if it finds a process
#with that name. It will also print out all the matching
#process IDs to the command line
pidof gulp
echo $? #1 if there is no process called gulp
#0 if there is a process called gulp
if pidof gulp; then
echo 'gulp is alive';
else
echo 'we need some support over here!'
./node_modules/.bin/gulp watch &
sleep 3
fi

Categories