Node-Webkit: Run application on download complete - node.js

I have created a Node-Webkit application and I am trying to implement application auto-update.
What I have done till now is:
I am checking version of my application's package.json with the package.json from server.
If they are different, I will download the new .exe from server.
It's downloaded to user-folder\AppData\Local\Temp\ folder
Now I want to close the application which is open and run the new exe file. But I want to do it pragmatically. Can anyone help me in doing this? Is there a way to open application when it's path is specified?
Any kind of help is appreciated. Thanks in advance

You can use spawn from the child_process API.
Spawn the new exe, detach it and unreference it, then close the current app.
Something like:
require("child_process").spawn('path/to/new/exe', [], {detached: true}).unref();
require('nw.gui').Window.get().close(true);

Related

Atom Electron cant find path of child process?

I built an app with electron and in the root directory I have a library. I want to run a child process from my app, so I use it like this:
spawn(path.resolve(LIB_PATH +'command_to_run')
This works when I run the app with npm start. But if I use electron-packager to make a build, it seems that it doesn't find the command. I receive this error:
Any ideas why this happens? I was researching a lot about it, but can't find anything.
Thanks
Found the solution. When I run npm start I can directly call ./command_to_run from the root of my project. But when I create a .app file, I need to add this: path.dirname(require.main.filename) + 'command_to_run'. Then it'll call the file that is in the root of my directory.

How do you set up file watcher in Webstorm to restart Node.js?

What I am trying to achieve is to trigger same behavior as Menu option Run > Run 'server.js'
Please try using Live Edit here - see http://blog.jetbrains.com/webstorm/2014/08/live-edit-updates-in-webstorm-9/. It allows re-starting node.js application on changing the code
You need to integrate webstorm with nodemon instead of the main node program. Basically nodemon is in charge of restarting your application and not webstorm.

ERROR: Can't set up Node.js core modules, when creating Node.js Express app on Webstorm

I am getting the following error when I try to create a Node.js Express app in Webstorm:
Can't set up Node.js v0.12.2 Core Modules Failed to create
C:\Users\Christina.WebStorm10\system\extLibs\nodejs-v0.12.2-src\core-modules-sources\lib\constants.js.
See idea.log for details (on the main menu "Help | Show Log in ...")
Does anyone know why?
Thanks in advance!
The reason is that access to this file is denied.
Remove nodejs-v0.xx.x-src folder, its default location is:
C:\Users\.IntelliJIdea14\system\extLibs
In the settings dialog select Languages & Frameworks > Node.js and NPM
Click on Configure button
In the new dialog accept defaults which is Download from the Internet.
Click on Configure button
I was having the same problem whenever I tried to download the modules Although I didnt find the reason for this I found a solution. Try to download Node.js from their website and use the Get Modules from Directory Option in the cofig window.
Then point the path to c:/Programs and Files(x86)/Node/npm and you should be good to go ;)

Installing a Web Server for Node.js

I'm trying to follow a book I purchased called "Pro Angular JS", and I am having trouble getting a web server pointed to the right port. So I go to the command line, run Node, and the first error I get is this, when trying to install connect:
npm should be run outside of the node repl, in your normal shell.
(Press Control-D to exit.)
Ok, fair enough. So I do as the command specifies, and I get it to install just as the user, and it ends up adding a folder called node_modules in my user root folder. Ok, seems like everything still makes sense.
Now, the book tells me to create a server.js file within the Node.js installation folder. There is no Node.js installation folder actually created on my user. I see the node_modules folder for sure. So I'm guessing the root directory of my user is where node.js was installed but maybe it's hidden or something? I believe when I used the Mac installer for Node, it said it was created at usr/local/bin. But I have no idea if that is my user on my computer, or even more root access to my computer.
Lastly, back to this server.js file...so I created it with a text editor, containing this code:
var connect = require('connect');
connect.createServer(
connect.static(".../angularjs")
).listen(5000);
And of course they want me to add this file to the directory where my Node is installed. Currently, it's sitting where my current user (user is kst001) root directory is. This is also where my node_module folder was created when I installed it using the npm install connect line in the shell. They also wanted me to create a folder called angularjs, where I would store my app, and said to place it in the root directory where node.js was installed. Once again, sitting in the root directory with everything else. Yet, when I try and fire up my test document in port 5000 (localhost:5000/test.html), I get a "could not find page" error.
Already tried using this link to solve my problem, which seems dead on for my issue, but it resolved nothing:
Node / connect issue Object function createServer has no method static
I'm using a Mac, by the way. Any ideas, guys? Any help would be much appreciated.
The reason why connect.static() does not work is that the latest major version of connect (3.x) no longer contains all of the middleware that connect was bundled with in 2.x.
The readme for connect has a list of middleware references that show you the name of the module on npm that gives you the old functionality for each middleware (e.g. static is now broken out into its own module serve-static).
I'm following the same book/example and the following works. I claim no credit, it is from another Stack Overflow answer about setting up a simple server plus the contents of a comment on the same answer (question 24346161 link to it from here: nodejs connect cannot find static)
Because I used it in exactly the same learning context (book I also purchased called "Pro Angular JS") and I have been around the houses for 3 hours trying to sort this out (yes a complete novice), I thought I would post it here.
firstly from your node installation directory
npm install serve-static
secondly, your node server.js code for a simple static server to serve your angularjs directory contents in a localhost:5000 browser window, on a Windows 7 machine should be (as at July 2015) ...
var connect = require('connect'),
serveStatic = require('serve-static');
var app = connect();
app.use(serveStatic("./angularjs"));
app.listen(5000);
I just stuck a simple index.html file in the angularjs directory to begin with containing
connection working
to test it and it worked a treat.

Including socket.io.js results in undefined 'require'

I've just started with node.js and socket.io.
I installed node.js using the windows installer, resulting in the following install path:
C:\Program Files (x86)\nodejs
I used npm to install socket.io and managed to include this in my server file, which is located in my projects folder, under
D:\projects\node\nodeserv.js
I then included the socket.io.js, which is located under the same socket.io folder, under the nodjs folder.
However, when I try to open the HTML file containing the client code, I get an error in socket.io.js stating:
Undefined reference to 'require'
Can someone help me out and see what I am doing wrong?
Make sure to check your spelling very carefully. If you can post post some code to look at, we can probably tell you the problem right away. More than likely it's a simple typo.
It sounds like you are trying to run node.js from the browser. Node.js runs on the server with the node executable. When you open the HTML file in your browser, it will execute the Javascript on it in a non node.js environment.
Apparently you need to get the socket.io.js file from the nodejs server.
So instead of an include, use an async call to get the file, like:
$.getScript('http://localhost:1337/socket.io/socket.io.js', function(){
//You can now use the io namespace
});

Resources