Disable livereload with Yeoman angular web app - node.js

I have a Yeoman web app up and running. It fails to retrieve livereload.js and can take up 21s before timing out and the page then goes on to load.
I don't even need the livereload functionality. This is a web app that is finished with development.
I use forever to start the web app. I navigate to the root folder of my app which contains my Gruntfile.js. I then run the command - forever start /usr/local/bin/grunt
What do I need to do to disable this livereload functionality?

You can disable running livereload server from the grunt file. However, that will still load the livereload js file in website footer and result in very slow page loads.
The reload script is being added from the server side. Edit the file server/config/express.js and comment out the line:
app.use(require('connect-livereload')());
Note: You seem to have bigger problems as well. You said, the site has completed development, but livereload works which is possible only when the server is running in development mode(unless you have edited Gruntfile to that effect). What you need is grunt serve:dist instead of simple grunt serve. Running the server in dev environment is a security as well as performance problem.
PS: I started with a similar set up but found later that sometimes the app.js will throw an error while grunt will continue running. This will put forever useless. You shall need the grunt-forever npm module to make sure forever is monitoring the right file.

Related

Express server is loading the app only the first time on port localhost:3000

I'm just starting with node.js and express.js and trying to create a listener with port 3000 using app.listen(3000).
The problem I'm having is when I first load the app, the browser loads it just fine, but when I make some changes, save the file and reload the browser, it doesn't show any changes. Mean it is just showing the first loaded version.
I have read many Q/A but none provide the specific solution. I don't know what I'm missing or doing wrong. Any help would be much appreciated, or please let me know if I explained my question properly.
You are looking for a tool like nodemon which does the server reloading. Unfortunately, nodemon doesn't reload the page itself, you still have to do it manually. Perhaps browsersync can help with that: it can be used for frontend development with live reloading, but I'm not sure if it works for fullstack reloading. The setup may depend on your pipeline (gulp/webpack/...), see for instance, this post for nodemon + gulp + browsersync combination.
you have to restart the server or install nodemon
This might be a problem with your computer console, probably be an old mac, because I face the same problem as well, try and destroy all node action by using killall node for mac and for window computer taskkill /im node.exe /F this will terminate all node action on your computer, after restart the node server this should work if it doesn't kindly comment below

Deploy Aurelia application on Heroku

I have an application using Node.js with Aurelia on the front-end, which I want to deploy on Heroku.
To run the app locally, I need to execute following commands:
1. npm start
2. cd public > gulp watch
After installing heroku-cli, tried publishing it using git push heroku master.
The problem is, Heroku only runs npm start when it's deploying the app on cloud. So it is able to start the server.
However, it doesn't know anything about cd public and gulp watch.
My question is, how can I tell Heroku to change directory to public and execute gulp watch command, once it has started the server?
Edit:
I forgot to address an important point. Since you only mentioned Aurelia in your question, I (wrongly) assumed that that's all you had.
Ultimately, for a production app you'll want to have a proper webserver hosting your Aurelia app.
Example:
For Aurelia apps I've built, I typically have 3 distinct processes running, each with their own port (or hostname):
IdentityServer
ASP.NET Web Api
OWIN FileServer
The third one is what hosts my Aurelia app as a static bundle.
There is no gulp or anything like that involved here. The server doesn't even have npm installed and sees it just like any other server-side application. And that's exactly how I deploy it; no node-related commands needed.
If you're using nodejs for your server-side stuff, use http-server to serve the static bundle.
When you host your aurelia app within your own serverside application you get the added benefit of being able to send some bootstrapping configuration directly along with the bundle, so you don't have to hard-code urls and such.
That's what I implied with "don't host a static site on heroku": bundle it up, and let your web application host it. My original answer would only apply if there is no server-side stuff involved.
Original answer:
It's generally not recommended to host static sites on heroku, see this blog post. The bottom line is that Aurelia sites are static, and a static site doesn't need an app server. It's unnecessarily expensive and doesn't have as good distribution as most CDNs do.
With that said, if you insist on hosting a static Aurelia site on Heroku then your best bet is to combine all your script calls into a single call which, as you say, already runs. So make your npm start script call gulp watch.
You'd probably want to npm install your dependencies and call ../node_modules/.bin/gulp watch instead of calling gulp globally.
When it comes to Heroku however, gulp watch in itself probably won't work because that will start a development server which will have no port binding in Heroku. It will run, but it won't be accessible from the outside.
gulp watch is not something you want to run on a server anyway because it will watch for file changes (which never happen there) and run things like browsersync which will be useless. Just bundle your app and start a normal http-server or better yet, upload the bundle ready-to-start into the correct folder and you're done.
You want to build your app and then deploy as if it were a fully-compiled, static application. With Aurelia CLI, that would be au build --env prod and then copy the scripts folder, index.html, and any dependencies like css, fonts, etc. to a separate folder. gulp build works the same way.
From there, you will publish the compiled app to Heroku as shown in this medium.com article:
https://medium.com/#winnieliang/how-to-run-a-simple-html-css-javascript-application-on-heroku-4e664c541b0b
The main part of the article is below, but here is the kicker - you are "tricking" heroku into thinking it is a PHP app. Serious!
Head to root directory of the repo that contains index.html which dictates the main HTML page.
Run touch composer.json to create a file called composer.json.
Add the following line: {} inside.
Run touch index.php to create a file called index.php.
Add the line: <?php include_once("index.html"); ?> inside.
Now update the repo on Github if it’s connected to your account or Heroku command git push heroku master . Wait for the automatic deploy to work its magic and tada!
There are some other steps to make your compiled app into a repo (ie, git init) but this should work for you. It did for me.

How to really debug node.js app?

I installed node-inspector.
I run it: node-debug app.js
But it opens the empty browser.
If I try to run node.js in debug mode before: node --debug app.js
It kind opens my scripts in browser.
But it's still not clear how to make it work. What to do next? Which url to use to see the working app itself in browser and trigger app to go to breakpoints?
My express app is usually running under localhost:3000. Should I run this url? It's not working.
Thanks
Okay,
I was able to figure it out. The problem was my app is Express based and it's a little bit different. For some reason it's not easy to find these differences until you start digging into every details. There is the instructions how to run debugger if you app is working under Express.
Prerequisites:
Windows 7
node.js app based on Express
Now:
Step 1. Run app in the debug mode (staying in the folder where your app.js located in the first command prompt), do either of 2: node --debug app.js or node --debug bin/www.
Step 2. Open the second command prompt and run node-inspector bin/www (or node-inspector app.js)
If you see the error that it can't access port 8080 it means that something is already listening to it. So you need to run this command differently: node-inspector --web-port=8099 bin/www
After step 1 you will able to run your app as usually in browser: localhost:3000.
After step 2 you open another browser window and enter: http://127.0.0.1:8099/?port=5858

Getting 502 error in browser for a NodeJS app run with Forever

I have a SailsJS app set up on a Webfaction server. Everything works nicely (site can be accessed through browser, console works) when I run the app via any of the following commands, with and without the --prod param:
sails console,
sails lift,
node app.js
However, when I try to run the app with forever using forever app.js I get a 502 error, as if nodejs server isn't even running. When I run forever list I can see app.js listed among running processes.
How can I have my app run with forever?
Forever is considered outdated by many in the Node community, and thankfully, has been replaced by several other fantastic (dare I say, better) tools.
If you're running a newer flavor of Ubuntu, you can always install systemd and kick off the application that way. If you're seeking something more streamlined, Phusion Passenger might be your ticket. It has a long track record of successes, and I wouldn't hesitate to toss it into production.
I managed to solve this issue; the problem occurred due to SailsJS migration prompt which shows up when you start the server. Running app.js with forever worked, but the server didn't start because the script hanged waiting for a prompt reply. If you encounter this issue just make sure you have your migrate option set in model config to avoid running into migration prompt.

how to keep a node server app running on windows server

I'm working on a project and I have modified node.js' 'simple chat room' sample application for my need, it works fine.
I have to call the server app's url (the .js file) to start it before opening the client page in the browser, so far everything works fine. But if the node server app goes down for any reason (server restart, iis restart, etc), the client page returns an error .
My question is, how can I keep the node server app alive all the time even after it interrupted. How can I do that without having a monitor or a script which runs every x minutes.
I'm using IIS 7.5 and iisnode module.
Thanks
Run your script file, as a service, with nssm.
Pretty sure you'll want jesus
Installation
$ npm install -g jesus
Usage
Start monitoring server
$ jesus daemon /path/to/server.log
To start a process
$ jesus start <id> node /path/to/my-app/index.js
To stop one
$ jesus stop <id>
To stop all
$ jesus stopall
I'm not sure about running node in iis. However, you can take a look at the node packages forever, pm2, and nodemon, which will recover the instance in case of failure.
Here's how to install node.js as a service
Here's something on installing node in iis 7.5
Just an update.
I've been using iisnode at work for the better part of a year. I would recommend it if you are deploying to Windows.
https://github.com/isaacs/node-supervisor and https://github.com/remy/nodemon have slightly different feature sets, but aren't Windows specific and still work on Windows unlike many of the other more popular, yet incomplete options such as forever and eternity (as of today anyway).

Resources