# Best Way to Execute Code on the First App Start Only

**URL:** <https://forum.ionicframework.com/t/best-way-to-execute-code-on-the-first-app-start-only/15490>\
**Category:** ionic-v1\
**Created:** [January 11, 2015, 4:35pm UTC](https://forum.ionicframework.com/t/best-way-to-execute-code-on-the-first-app-start-only/15490 "2015-01-11T16:35:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rmtuckerphx](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@rmtuckerphx](https://forum.ionicframework.com/u/rmtuckerphx)\
**Post date:** [January 11, 2015, 4:35pm UTC](https://forum.ionicframework.com/t/best-way-to-execute-code-on-the-first-app-start-only/15490/1 "2015-01-11T16:35:30Z")

</div>

When my app starts for the very first time only, I want to execute some code.

Do you have a code sample that shows how to do this with Ionic?

---

<div class="post-metadata">

**Author:** ![lytvynenko](https://avatars.discourse-cdn.com/v4/letter/l/ce73a5/32.png) [@lytvynenko](https://forum.ionicframework.com/u/lytvynenko)\
**Post date:** [January 11, 2015, 10:03pm UTC](https://forum.ionicframework.com/t/best-way-to-execute-code-on-the-first-app-start-only/15490/2 "2015-01-11T22:03:48Z")

</div>

Actually you don’t need any specific stuff in ionic. Just use some value stored into localStorage and check it somewhere in the app.run().

```
 angular.module('myApp').run(function(){
    if (window.localStorage && !window.localStorage.getItem('firstRunFinished')) {
      // DO HERE WHAT YOU WANT TO DO ON THE FIRST RUN
      // ....
      // now store value into localStorage
       window.localStorage.setItem('firstRunFinished',true);
    }
});
```
