Hi, I’m new using Ubuntu Core and Snap development, I would like to have some guidance on how to create a Snap that contain a REST API built in Node.js I created a very very simple API:
const express = require('express');
const app = express();
var cors = require('cors');
const port = 3000;
app.use(cors());
app.get('/', (req, res) => res.send('Hello World!'));
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
I don’t really know how to configure the snapcraft.yaml file to make this work, I check there is an npm plugin but it does not work for me, also I don’t know how to setup the snap so it runs like a deamon and in start it runs npm run start
from a package.json script.
I will really appreciate any help you can provide me. Thanks in advanced
– EDIT –
I’m trying with the snapcraft.yaml with this configuration:
name: snap-hello-api # you probably want to 'snapcraft register <name>'
base: core22 # the base snap is the execution environment for this snap
version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
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 # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots
parts:
snap-hello-api:
plugin: npm
npm-node-version: 18.16.0
source: .
apps:
snap-hello-api:
daemon: simple