Media Library Step 1: Configuring the Back End
As mentioned earlier, we'll be using TypeScript and node.js. You have two options here; you can install the npm packages manually, or just copy our package.json file and enter npm install
. If you want to install them manually, start by typing
npm init
and answer the defaults to the questions, except for "type" make it "module".
Next, type
npm install cors express golem-base-sdk multer sharp tslib
(multer will allow us to read in the form data; sharp is the image processing library we'll use.)
Next install the developer dependencies:
npm install -d @types/cors @types/express @types/multer @types/node @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint eslint-config-prettier prettier ts-node typescript
(The packages that mention eslint and prettier in their names are optional.)
Note: We also include some helper scripts that you can manually add to the package.json if you prefer; see the scripts member in the package.json file below.
And finally, if you prefer to just copy and paste the package.json file, here it is:
{
"name": "backend",
"version": "1.0.0",
"description": "",
"license": "ISC",
"author": "",
"type": "module",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc; cp ./private.key dist",
"start": "node dist/index.js",
"build-and-start": "npm run build && npm run start",
"dev": "ts-node src/index.ts",
"lint": "eslint \"src/**/*.ts\"",
"lint:fix": "eslint \"src/**/*.ts\" --fix",
"format": "prettier --write \"src/**/*.ts\""
},
"dependencies": {
"cors": "^2.8.5",
"express": "^5.1.0",
"golem-base-sdk": "^0.1.16",
"multer": "^2.0.2",
"sharp": "^0.34.3",
"tslib": "^2.8.1"
},
"devDependencies": {
"@types/cors": "^2.8.19",
"@types/express": "^5.0.3",
"@types/multer": "^2.0.0",
"@types/node": "^24.0.13",
"@typescript-eslint/eslint-plugin": "^8.39.0",
"@typescript-eslint/parser": "^8.39.0",
"eslint": "^9.32.0",
"eslint-config-prettier": "^10.1.8",
"prettier": "^3.6.2",
"ts-node": "^10.9.2",
"typescript": "^5.8.3"
}
}
Next, you'll need to create a file called tsconfig.json
. Here's the text to put in the file:
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "Node",
"strict": true,
"esModuleInterop": true,
"outDir": "dist",
"rootDir": "src",
"resolveJsonModule": true
},
"include": ["src"]
}
Next, create a folder called src; this is where you'll be putting the TypeScript source code. (As per the tsconfig.json file, the generated javascript code will go in a folder called dist
. TypeScript will create that folder for you.)
Now copy your private.key file to this folder; notice in our build script we're copying it into the dist folder. The reason we advise against simply putting it in the dist folder is since the dist folder is automatically created, we're assuming it could be deleted at any time by you or another developer.
And finally, if you're adding a .gitignore file, we recommend the following at a minimum:
private.key
wallet.json
dist/
node_modules/
Head to Step 2.