Setting up your local environment

Check system requirements

Before we get started, make sure you’ve got the following installed:

Install Docker
Install pack

First, we’ll create a sample nodeJS app that you can use when developing your buildpack:

mkdir node-js-sample-app

Create a file in the current directory called node-js-sample-app/app.js with the following contents:

const http = require('http');
 
const hostname = '0.0.0.0';
const port = 8080;
 
const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World!');
});
 
// For demo purposes we do not actually start the server.  This
// allows us pretend to start the server and check if the output
// message is correct.
//server.listen(port, hostname, () => {
//  console.log(`Server running at http://${hostname}:${port}/`);
//});
console.log(`Server running at http://${hostname}:${port}/`)

We also create a package.json file with the following contents:

{
  "name": "example-application"
}

Finally, make sure your local Docker daemon is running by executing:

docker version

If you see output similar to the following, you’re good to go! Otherwise, start Docker and check again.

Client: Docker Engine - Community
 Version:           20.10.9
 API version:       1.41
 Go version:        go1.16.8
 Git commit:        c2ea9bc
 Built:             Mon Oct  4 16:08:29 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.9
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.8
  Git commit:       79ea9d3
  Built:            Mon Oct  4 16:06:34 2021
  OS/Arch:          linux/amd64
  Experimental:     false

Next Step