Creating an expressjs snap

I am on way to create an expressjs snap (first time), but my application wants to write to a file. When I try that it’s giving a read only file system error.

Error writing sample file [Error: EROFS: read-only file system, open ‘/snap/sample-express/x1/lib/node_modules/sample-express/sample.txt’]

my snapcraft file looks like this:

version: '1.0'
summary: Sample snap
description: |
  Desc
base: core20

grade: devel

confinement: devmode

parts:
  sample-express:
    plugin: npm
    npm-node-version: 15.13.0
    source: .

apps:
  sample-express:
    command: bin/sample-express

=======================

Have anyone faced this issue before? Any help in this regard will be awesome.

make your app read the environment variable $SNAP_DATA (if it runs as a daemon) or $SNAP_USER_DATA (if it is started by a user) and adjust your code to write to the dir that variable gives you …

also when posting yaml, please put three backticks ``` above and below the pasted code so the indendation and formatting persists in the forum post :slight_smile:

thanks @ogra for your reply
how will my express js know this $SNAP_USER_DATA location? What path should I use in my application?

on side note, how can I run this expressjs app as daemon, so that once snap is installed it starts running?

i havent used express.js a lot, in nodejs you’d do smething like writable_path = process.env.SNAP_DATA in your code and then use writable_path as target directory

I have been trying to build a snap for NestJS backend as a daemon, What is in your package.json the command bin/sample-express just launch the server entry point?