node.jsnpmelectronsinopia

Node registry path with electron-updater and Sinopia


I am currently working on an application running on Electron (former atom-shell), and trying to design a way to alert the user when a new update is available. To do this, I am using electron-updater in the way described in electron-updater-sample. I also configured Sinopia to be listening on http://localhost:4873/ (default behavior) and ran this commande line:
npm config set registry "http://localhost:4873" I checked in the .npmrc file, the registry is properly set with the new value.
The problem I have is when I try to check for the update, I get this error message in console:

{ [HTTPError: Response code 404 (Not Found)]
message: 'Response code 404 (Not Found)',
code: undefined,
host: 'registry.npmjs.org',
hostname: 'registry.npmjs.org',
method: 'GET',
path: '/hacker-keyboard-electron',
statusCode: 404,
statusMessage: 'Not Found' }

So I believe I forgot something in the configuration of npm that makes the application listen to the regular path for npm rather than the Sinopia server. The question is what?
Please find below the code I am using:

foobar-generator
├── app
├── bower components
├── bower.json
├── index.html
├── index. js
├── main. js
├── nbproject
├── node modules
├── npm-debug.log
├── package.json
├── readme. md
└── sinopia

package.json

{
    "name": "foobar-generator",
    "version": "0.0.1",
    "description": "A generator for foobar",
    "main": "main.js",
    "dependencies": {
        "angular": "^1.4.7",
        "bootstrap": "^3.3.5",
        "chokidar": "^1.2.0",
        "electron-debug": "^0.2.1",
        "electron-packager": "^5.1.0",
        "electron-plugins": "^0.0.4",
        "electron-prebuilt": "^0.33.6",
        "electron-rebuild": "^1.0.2",
        "electron-updater": "^0.2.0",
        "grunt": "^0.4.5",
        "jquery": "^2.1.4"
    },
    "devDependencies": {},
    "publishConfig": {
        "registry": "http://localhost:4873/"
    },
    "registry": "http://localhost:4873/"
}

main.js

var appli = require('app');
var BrowserWindow = require('browser-window');
var updater = require('electron-updater');
var util = require('util');

// Report crashes to our server.
require('crash-reporter').start();

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
var mainWindow = null;
var loaded = false;

// Quit when all windows are closed.
appli.on('window-all-closed', function () {
    // On OS X it is common for applications and their menu bar
    // to stay active until the user quits explicitly with Cmd + Q
    if (process.platform !== 'darwin') {
        appli.quit();
    }    
});

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
appli.on('ready', function () {
    updater.on('ready', function () {
        // Create the browser window.
        mainWindow = new BrowserWindow({width: 800, height: 600});

        // and load the index.html of the app.
        mainWindow.loadUrl('file://' + __dirname + '/index.html');

        mainWindow.openDevTools({detach: true});

        mainWindow.on('closed', function () {
            mainWindow = null;
        });
    });
    updater.on('updateRequired', function () {
        appli.quit();
    });
    updater.on('updateAvailable', function () {
        if (mainWindow) {
            mainWindow.webContents.send('update-available');
        }
    });
    updater.start();
    updater.check(function (err, results) {
        if (err) {
            return console.error(util.inspect(err));
        }
        console.log(results);
    });
});

Do you guys see anything I could have forgotten/done wrong?


Solution

  • By reading the manual for npmrc (npm help npmrc), I have discovered the the .npmrc file is not unique. By configuring the registry the way I did, I only changed the per-user .npmrc. But there also should be such a file in your project root directory! It is in this one that you should configure the registry you want to use. Adding this file in project root directory solved the problem I was facing.