Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to run nodejs app as a desktop application using electron

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 464
    Comment on it

    Hi All,
    While working on one of my project we had a requirement where we need to run our web application as a desktop application and to do that we found a solution called Electron which can w=be used as an installer and it run on various plate forms like MAC, Windows and Linux.

     

    Now what is Electron and how we can use it to create an installer to run our app as a desktop application on various platform?

    Electron is a tool which come with built-in io.js and Chromium which is built on V8 JavaScript Engine which is an open source JavaScript engine developed by The Chromium Project for the Google Chrome web browser.

    Electron relies on the Squirrel framework and It takes care of creating the actual package, signing it, dealing with updates, and many more things. 

    So the first this you need to have to get started is to install the Electron Packager and to do that you need to open the cmd/terminal (in case of mac) and run the command :

    npm run i electron-packager --save -dev 

    Bellow is the code for the sample app that you can go ahead and create :

    in Index.html we have :

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="UTF-8">
        <title>Hello World!</title>
      </head>
      <body>
        <h1>Hello World!</h1>
        We are using node <script>document.write(process.versions.node)</script>,
        Chromium <script>document.write(process.versions.chrome)</script>,
        and Electron <script>document.write(process.versions.electron)</script>.
      </body>
    </html> 

     

    In the package.json we have :

    {
      "name": "electron-quick-start",
      "version": "1.0.0",
      "description": "A minimal Electron application",
      "main": "main.js",
      "scripts": {
        "start": "electron main.js"
      },
      "repository": {
        "type": "git",
        "url": "git+https://github.com/electron/electron-quick-start.git"
      },
      "keywords": [
        "Electron",
        "quick",
        "start",
        "tutorial"
      ],
      "author": "GitHub",
      "license": "CC0-1.0",
      "bugs": {
        "url": "https://github.com/electron/electron-quick-start/issues"
      },
      "homepage": "https://github.com/electron/electron-quick-start#readme",
      "devDependencies": {
        "electron-prebuilt": "^0.37.0" 
      }
    }

     

    and to run this we need to navigate to electron-quick-start folder and then run command

    npm install

    and than to run the app, you need to run the command

    npm start

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: