I'm using ES6 with babel-node to create my app and I require my app to start with the command babel-node app.js. This command is listed in scripts: start in my package.json so the command npm start runs the correct command.
Open shift starts node apps with node + what ever script is set in the main property of your package.json file. In my case its "main": "app.js". So this command is run node app.js.
The server is choking on the first ES6 it encounters which makes sense. I can't figure out how to configure openshift to run babel-node or npm start to start up my app.
Here is my package.json file -> https://gist.github.com/jkinman/2cc57ce5fae5817d6bca
You shouldn't run your server with babel-node, which is memory intensive and not meant for production. Instead, you should use the require hook by creating a file start.js (name unimportant) with the following content:
require('babel-core/register')
require('./app.js')
// or server.js or whatever you use to normally start you app
Then you can start your server with node start.js.
Related
In my ec2 instance I am able to run pm2 command.
But while deploying application through code deployment I get this error.
LifecycleEvent - ApplicationStop
Script - application_stop.sh
[stdout]Stopping any existing node servers
[stderr]/opt/codedeploy-agent/deployment-root/878477e5-6ffb-4175-8e9e-97045ea99290/d-HVRQ58IBL/deployment-archive/application_stop.sh: line 4: pm2: command not found
My application_stop.sh code.
#!/bin/bash
#Stopping existing node servers
echo "Stopping any existing node servers"
pm2 stop main
As per #ranjanistic I checked my pm2 path using which pm2 command and it returned
~/.nvm/versions/node/v16.15.1/bin/pm2
After that I update my application_stop.sh using this below command
~/.nvm/versions/node/v16.15.1/bin/pm2 start main
Also added symbolic link like this to npm, node and pm2.
///this process worked. Thanks #ranjanistic
which npm
which node
which pm2
sudo ln -s /home/ec2-user/.nvm/versions/node/v16.15.1/bin/npm
sudo ln -s /home/ec2-user/.nvm/versions/node/v16.15.1/bin/node
sudo ln -s /home/ec2-user/.nvm/versions/node/v16.15.1/bin/pm2
Still not working
The binary executable reference to your command needs to be available in the environment you're expecting to run it from.
You are using npm to run a pm2 command, which means it is installed as a local module. Therefore you can similarly create another npm script like npm run stop:all with your pm2 command, it should work.
If you're running it in a bash script, the command reference binary should be available in PATH. Or you can also use your command by mentioning its binary path instead of name, independent of wherever the binary is located, for example
If pm2 is installed as a global node module
/usr/bin/pm2 stop main # or whatever the path to the binary is.
Or if pm2 is installed as a node module in project then
./node_modules/bin/pm2 stop main # again, path to pm2 binary can be anything, you'll have to know beforehand
Also, I'd recommend a separate config file for each of your pm2 applications, so that you can use it anywhere without worrying whether your main app is available to pm2 or not.
You may also need to check if npm or node commands are running or not, and based on that you may add the path to your folder containing pm2 in $PATH variable before running the deployment. You can check the path to pm2 manually using which pm2 if it is available.
You need to provide absolute path like this /usr/bin/pm2
I have three files
-- Index.js
-- Node Modules
-- Package.json
I need to run this project I am using
npm start
But getting the below error
npm ERR! missing script: start
Then i have used the below command in package.json
start:"node index.js"
Then the project is running but coming out of loop like the below
admin#DESKTOP-ASA7V3C MINGW64 /e/Trigger Email Fucntion
$ npm start
> skill-sample-nodejs-fact-i18n#2.0.0 start E:\Trigger Email Fucntion
> node index.js
Loading function
admin#DESKTOP-ASA7V3C MINGW64 /e/Trigger Email Fucntion
$
So please help me how to start the node js project and not to stop unless we stop it
Expected Result :
The project needs to run by using npm start
What you're experiencing is the expected behaviour, code exits once it's execution is complete. You can use nodemon, it will detect the changes and automatically start the node application. I hope this is what you're looking for.
I'm just starting to learn about how JavaScript, HTML, and Electron all work, and I want to know what runs electron . in the "scripts" -> "start" of package.json, because I can't tell what does and that kind of wizardry makes me nervous.
According to the man pages for npm, what npm start does is that it reads the package.json, looks at the script under "scripts" -> "start" -> some_script, and then runs some_script. Sometimes, some_script is something like node foobar.js, which makes sense to me, since I can run that from the command line. NodeJS is executing foobar.js. However, in the case of the electron-api-demos, some_script is electron .
You can download and run electron-api-demos via
git clone https://github.com/electron/electron-api-demos
cd electron-api-demos/
npm install && npm start
In order to try to figure out what is running electron ., I've run it in the node shell, and I've tried running node main.js. I've even tried opening up the node shell and running
electron-api-demos#2.0.2 start $DIR/electron-api-demos
electron .
(which is exactly the output of npm start). None of them worked, because none of them started up the Electron application. At this point I'm very puzzled at how, exactly, the start script gets executed at all.
So I guess my question is: does there exist a command (that I can use on the command line) to start up this Electron application, without using npm? If not, what is npm calling to start up this Electron app?
I apologize if this question has been asked before, but I all the sources I found didn't seem to go into any further detail about what, exactly, is done when npm start is run and how it executes electron . . Thank you for your time!
Command line interfaces installed with npm are put in the node_modules/.bin/ directory. You can't just run them from the command line because that directory isn't in your PATH (unless you put it there, or you installed it globally).
So, if you want to run electron without npm start, you can run ./node_modules/.bin/electron .. Since this is a bit verbose, newer versions of npm provide the command npx to run things without the ./node_modules/.bin/ part, so npx electron . also works.
Since npm scripts often use the packages you've installed, they automatically add node_modules/.bin/ to the PATH before running your command. As a result, the start script can just reference electron directly.
npx can do some other cool things too – npm has a blog post about it.
When you run npm start , it by default run command corresponding "start" key of script property of package.json like
"script":{
"start": "ng serve",
"launch":"electron main.js" or "electron ." // main.js located in the same dir
"test": " ng test"
}
same when you run npm run launch it will trigger the command corresponding of the "launch" key of script property of package.json file. like run electron main.js command and your application will launched.
so if you want to run the your electron application directly like electron main.js then install the electron module globally using command npm install electron -g then simply run the electron main.js command and your application will start.
I'm new to use cordova.One way to live reload cordova app I know is to use plugin 'cordova-plugin-browsersync'.But My App was built by webpack,now I want to live reload in Browser,I must run 'webpack-dev-server' first and run 'cordova run browser -- --live-reload'.Can I achive the function to Live Reload more easy and debug live reload in emulator?
I used npm package live-server to handle the reloading for the browser platform. Have it watch the platforms/browser/www directory. Your build system likely has a watch mode, in which it can detect changes and output the compiled result as well. You also need to call cordova prepare after your build finishes, which can be achieved with nodemon.
To put it all together in a full example:
Have your source code in /src.
Run your build tool in watch mode (ex, webpack --watch, or parcel --watch) and output to /www
Run nodemon watching /www and have it run cordova prepare. The prepare command will copy your files from www to your platform directories. (ex: nodemon --watch www --exec \"cordova prepare\")
Run live-server watching the /platforms/browser/www folder
Viola!
This results in a semi-fast live-reload environment with cordova in the browser platform. As this is a lot of things to run at once, you can run all of your scripts in parallel using npm-run-all.
A final script in package.json might look like this:
"scripts": {
"live-build": "webpack --watch --output-path=www ....",
"live-watch": "nodemon --watch www --exec \"cordova prepare\" --ext html,css,js",
"live-serve": "live-server --watch=\"platforms/browser/www\"",
"start": "npm-run-all -c -n -l -p live-build live-watch live-serve"
}
And then you'd just call npm start to run your entire live-reload environment. This will need to be tweaked for your specific project but should give you a general idea of how it could be accomplished.
I just ran into the same problem and yet haven't found a ready solution, so below is what I did and further steps of my plan to solve it.
I've downloaded cordova-plugin-browsersync
cordova plugin add cordova-plugin-browsersync didn't work, so I manually copied it to plugins folder, updated cordova's package.json and installed the plugin's node modules from cordova-plugin-browsersync folder.
After that the app seems to update pretty fast if anything is modified in the www folder.
Now have to solve how to output intermediate bundle files from webpack-dev-server, which it doesn't do by default. I've found write-file-webpack-plugin, but it's not outputting all the files to the build folder, so might not work very well for this purpose.
So my plan is to
create a webpack.config.cordova.js file where code compression is off
setup any app that watches the src folder and calls a node.js script
which script programmatically compiles with that webpack config, outputting to cordova's www/
I have a node.js application that I start using forever like so:
NODE_ENV=production forever start index.js
I've also worked out how to setup crontab to automatically start the forever command for this application on server reboot:
#reboot /usr/local/bin/forever start /path/to/my/app/index.js
The only problem here is the node environment. How do I add the production environment to the crontab command?
If you want to set just one environment variable, you could use the export command right before the forever command.
#reboot export NODE_ENV=production; /usr/local/bin/forever start /path/to/my/app/index.js
For more than one variable Sukima's method is better.
If you need to execute a special command with variables etc. in a crontab it's easier to write a simple shell script and call that script from the crontab:
#!/bin/bash
export NODE_ENV=production
/usr/local/bin/forever start /path/to/my/app/index.js
Make it executable: chmod 755 /usr/local/bin/start_my_app.sh
Then in your crontab:
#reboot /usr/local/bin/start_my_app.sh