Node.js REST API packed as Snap

In case someone is wonder this same question, I did make it work and it was absolutely simpler than expected:

This is my snapcraft.yaml configuration:

name: snap-hello-api
base: core22
version: '0.1'
summary: Node.js REST API packaged as snap # 79 char long summary
description: |
  Snap that publish a Node.js REST API that listen for GET request

grade: devel 
confinement: devmode

parts:
  snap-hello-api:
    plugin: npm
    npm-include-node: true
    npm-node-version: 18.16.1
    source: .
apps:
  snap-hello-api:
    command: bin/start
    daemon: simple

Two other couple of things to make it work was, in the package.json include “bin”

"bin": {
    "start": "app.js"
  },

And in the app.js include the header:

#! /usr/bin/env node

The example can be found in this public repo: https://github.com/jperera84/snap-hello-api

I hope this help!!

2 Likes