# Persistent state in Node.js

<p class="callout info">This article was originally published at [https://gist.github.com/joepie91/bf0813626e6568e8633b](https://gist.github.com/joepie91/bf0813626e6568e8633b).</p>

<div class="Box-body readme blob p-5 p-xl-6 gist-border-0" id="bkmrk-this-is-an-extremely"><article class="markdown-body entry-content container-lg">This is an extremely simple example of how you have 'persistent state' when writing an application in Node.js. The `i` variable is shared across all requests, so every time the `/increment` route is accessed, the number is incremented and returned.

This may seem obvious, but it works quite differently from eg. PHP, where each HTTP request is effectively a 'clean slate', and you don't have persistent state. Were this written in PHP, then every request would have returned `1`, rather than an incrementing number.

</article></div>```javascript
var i = 0;

// [...]

app.get("/increment", function(req, res) {
      i += 1;
      res.send("Current number: " + i);
})

// [...]
```