Skip to content

Setting up a TypeScript Environment

This will typically apply to the backend of your full-stack app.

Here are the steps for creating a new TypeScript project from scratch. (You can optionally download a skeleton app here and skip the below steps; if you do so, however, remove the .git folder .)

We're assuming you've already created a folder/directory for your app, and that you've added a git repo if necessary.

Create the package.json file

(If you downloaded the skeleton repo, you can skip this step.)

Create an npm package.json file:

npm init

Important

When asked for the type attribute, change it from commonjs to module.

Next,

EITHER run the following npm install lines:

npm install golem-base-sdk tslib dotenv ethers xdg-portable

npm install -d @types/node @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint eslint-config-prettier prettier typescript

OR simply grab them from the full package.json file below, paste them into your own package.json, and then run

npm install

Script lines

Although optional, we recommend adding the script lines as shown in the full package.json file below.

package.json

Here is the resulting package.json file:

{
  "name": "your-app-name",
  "version": "1.0.0",
  "description": "",
  "license": "ISC",
  "author": "",
  "type": "module",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "tsc",
    "start": "node dist/index.js",
    "build-and-start": "npm run build && npm run start",
    "lint": "eslint \"src/**/*.ts\"",
    "lint:fix": "eslint \"src/**/*.ts\" --fix",
    "format": "prettier --write \"src/**/*.ts\""
  },
  "dependencies": {
    "dotenv": "^17.2.1",
    "ethers": "^6.15.0",
    "golem-base-sdk": "^0.1.16",
    "tslib": "^2.8.1",
    "xdg-portable": "^10.6.0"
  },
  "devDependencies": {
    "@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",
    "typescript": "^5.8.3"
  }
}

TypeScript configuration

(If you downloaded the skeleton repo, you can skip this step.)

Next, add a TypeScript config file by creating a new file called tsconfig.json and adding the following to it:

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "ESNext",
    "moduleResolution": "Node",
    "strict": true,
    "esModuleInterop": true,
    "outDir": "dist",
    "rootDir": "src",
    "resolveJsonModule": true
  },
  "include": ["src"]
}

Src folder creation and initial index.ts file

(If you downloaded the skeleton repo, you can skip this step.)

Next, create a folder/directory called src:

mkdir src

and create a file in src called index.ts and just put a single line in it for now:

console.log('Code coming soon!')

That's where you'll put your initial TypeScript code.

Test it out

Verify everything works by typing:

npm run build-and-start

You should see output that ends with:

Code coming soon!

Git-ignore creation

Finally, if you're planning to create a git repo but haven't yet, go ahead and do so now by typing:

git init
git branch -m main

you'll want to create a .gitignore and place it in the root folder of your project. We recommend starting with this one:

https://github.com/github/gitignore/blob/main/Node.gitignore

and then adding a couple items to the top of it:

private.key
wallet.json

Or if you're rolling your own, you'll want at least the following in your .gitignore:

private.key
wallet.json
dist/
node_modules/

Ready to go!

Now you can start building your TypeScript app!