<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ create-elm-app - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ create-elm-app - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Fri, 19 Jun 2026 16:03:01 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/create-elm-app/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to use Netlify Functions in Elm ]]>
                </title>
                <description>
                    <![CDATA[ This worked example creates a simple Netlify Function and integrates it with an Elm application. Netlify functions provide a very convenient way of working with AWS Lambdas, and they have an impressive array of example use cases, such as sending emai... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-use-netlify-functions-in-elm/</link>
                <guid isPermaLink="false">66bb926adeef71ff683a6d46</guid>
                
                    <category>
                        <![CDATA[ create-elm-app ]]>
                    </category>
                
                    <category>
                        <![CDATA[ netlify-functions ]]>
                    </category>
                
                    <category>
                        <![CDATA[ aws lambda ]]>
                    </category>
                
                    <category>
                        <![CDATA[ ELM ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Netlify ]]>
                    </category>
                
                    <category>
                        <![CDATA[ serverless ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Cedd Burge ]]>
                </dc:creator>
                <pubDate>Wed, 28 Aug 2019 07:37:39 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/08/netlify-functions-elm.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>This worked example creates a simple <a target="_blank" href="https://functions.netlify.com/">Netlify Function</a> and integrates it with an Elm application.</p>
<p>Netlify functions provide a very convenient way of working with AWS Lambdas, and they have an <a target="_blank" href="https://functions.netlify.com/examples">impressive array of example use cases</a>, such as sending emails, processing payments and logging.</p>
<p>This example reads secrets from environment variables (to avoid them being exposed in the browser), but it is mostly generic, and can be adapted for other use cases easily.</p>
<h2 id="heading-step-1-prerequisites">Step 1 - Prerequisites</h2>
<ul>
<li>Create a repository for the code, probably on GitHub</li>
<li><code>npm i -g elm</code></li>
<li><code>npm install -g netlify-cli</code></li>
<li><code>npm i -g create-elm-app</code></li>
</ul>
<h2 id="heading-step-2-create-vanilla-elm-app">Step 2 - Create vanilla Elm app</h2>
<ul>
<li><code>create-elm-app elm-app-with-netlify-function</code></li>
<li><code>cd elm-app-with-netlify-function</code></li>
<li><code>elm-app start</code></li>
</ul>
<p>This should start a development server and load the app in your browser.</p>
<p>You can look at <a target="_blank" href="https://github.com/ceddlyburge/netlify-functions-with-elm/commit/d976b2391f98f07113d1e41a64b0359caddf3452">this commit in the companion repository</a> to check that everything is ok.</p>
<h2 id="heading-step-2-deploy-on-netlify">Step 2 - Deploy on Netlify</h2>
<ul>
<li><code>npm init</code> (and fill in sensible values)</li>
<li><code>npm i create-elm-app --save-dev</code> (this adds create-elm-app to package.json, which is used by netlify)</li>
<li>Push the code to GitHub</li>
</ul>
<p>You can see the results of this at <a target="_blank" href="https://github.com/ceddlyburge/netlify-functions-with-elm/commit/aa52ccfabacae69591a920f0675eedf620ae8b03">this commit in the companion repository</a></p>
<ul>
<li>Log in / Sign up / register with <a target="_blank" href="https://www.netlify.com/">Netlify</a></li>
<li>Create a <a target="_blank" href="https://app.netlify.com/start">new site</a> on Netlify</li>
<li>Choose your repository</li>
<li>Set the "Build command" to <code>elm-app build</code></li>
<li>Set the "Public directory" to <code>build</code></li>
<li>Click on "Deploy Site"</li>
</ul>
<p>Netlify will now deploy the site, installing the dependencies specified in package.json, then running <code>elm-app build</code> and then serving the dist directory.</p>
<p>From now on, Netlify will attempt to deploy the latest code every time you push to GitHub.</p>
<h2 id="heading-step-3-link-netlify-dev">Step 3 - Link Netlify Dev</h2>
<ul>
<li><code>netlify login</code></li>
<li><code>netlify link</code> and choose the “Use current git remote url” option</li>
<li>Add “./netlify” to .gitignore</li>
<li>Add a netlify.toml file (from <a target="_blank" href="https://github.com/ceddlyburge/netlify-functions-with-elm/commit/6514012000ea82fb6625fa3686adafa321723d28">this commit in the companion repository</a>)</li>
<li><code>netlify dev</code></li>
</ul>
<p>This should start a local development server and load the app in your browser, in a similar way to step 1.</p>
<h2 id="heading-step-4-add-a-netlify-function">Step 4 - Add a netlify function</h2>
<p>Run <code>netlify functions:create</code> to create a new netlify function. Choose the “js-token-hider” template, and name it "call-api".</p>
<p>This will create a javascript file for the function, and a package.json for its dependencies in “functions/call-api”.</p>
<p>Replace functions/call-api/call-api.js with this one in <a target="_blank" href="https://github.com/ceddlyburge/netlify-functions-with-elm/commit/79381b9c1a7731b01f0c81b58a772d9576f76732">the companion repository</a></p>
<p>Now if you run <code>netlify dev</code>,  the function will be served as well as the app, albeit on different  ports. You can view the function in the browser to check that it is  working (probably at <a target="_blank" href="http://localhost:34567/call-api">http://localhost:34567/call-api</a> or <a target="_blank" href="http://localhost:34567/.netlify/functions/call-api">http://localhost:34567/.netlify/functions/call-api</a>)</p>
<h2 id="heading-step-5-call-the-netlify-function-from-elm">Step 5 - Call the netlify function from Elm</h2>
<p>Install depdencies</p>
<ul>
<li><code>elm install elm/json</code></li>
<li><code>elm install elm/http</code></li>
<li><code>elm install krisajenkins/remotedata</code></li>
</ul>
<p>Update Main.elm to call the function and display the results (from <a target="_blank" href="https://github.com/ceddlyburge/netlify-functions-with-elm/commit/4dc9e8e4b60d061b5d5ef0fb2ce6ab856741236f">the companion repository</a>).</p>
<p>Instruct create-elm-app to proxy api calls to the function, by adding elmapp.config.js, as shown in <a target="_blank" href="https://github.com/ceddlyburge/netlify-functions-with-elm/commit/90a63178e38f2919770e37fcc94e7ee0bec343ab">the companion repository</a>.</p>
<p>At  this point, thee application runs, and successfully calls the api, but  there are no secrets / environment variables yet, so the UI shows an error.</p>
<h2 id="heading-step-6-add-the-secrets">Step 6 - Add the secrets</h2>
<p>Go  to the “Site Settings” - “Build &amp; Deploy” - “Continuous Deployment”  - “Environment Variables” section on the Netlify website for your application.</p>
<p>Add environment variables for API_TOKEN and API_URL</p>
<p>Now when you run ‘netlify dev’ the app should now load in the browser and call the locally hosted netlify function, which will return the API_TOKEN and API_URL environment variables that you set on Netlify.</p>
<p>The  same should be true on the live deployment on Netlify. You may need to  “Trigger Deploy” manually on Netlify, so that it uses the new environment variables.</p>
<p>You can see the deployment of the companion repository at <a target="_blank" href="https://netlify-functions-with-elm.netlify.com">https://netlify-functions-with-elm.netlify.com</a></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Netlify  / serverless functions are extremely useful for creating / connecting to the backend services that your front end needs. They are also very east to set up, as this artcile (hopefully!) shows.</p>
<p>Create-elm-app is a great tool for developing Elm applications, and its simple proxy feature works well when developing Netlify functions.</p>
<p>Netlify Dev is great for replicating the production Netlify setup when developing locally (in this case by automatically providing the environment variables).</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
