klfwdh
Try for free
No credit card required
Go to Store
klfwdh
expressive_coast/my-actor-1
Try for free
No credit card required
.editorconfig
1root = true
2
3[*]
4indent_style = space
5indent_size = 4
6charset = utf-8
7trim_trailing_whitespace = true
8insert_final_newline = true
9end_of_line = lf
.eslintrc
1{
2 "extends": "@apify/eslint-config-ts",
3 "root": true,
4 "parserOptions": {
5 "project": "./tsconfig.eslint.json"
6 }
7}
Dockerfile
1# using multistage build, as we need dev deps to build the TS source code
2FROM apify/actor-node:16 AS builder
3
4# copy all files, install all dependencies (including dev deps) and build the project
5COPY . ./
6RUN npm install --include=dev \
7 && npm run build
8
9# create final image, copy only package.json, readme and compiled code
10FROM apify/actor-node:16
11# copy only necessary files
12COPY /usr/src/app/package*.json ./
13COPY /usr/src/app/README.md ./
14COPY /usr/src/app/dist ./dist
15COPY /usr/src/app/INPUT_SCHEMA.json ./INPUT_SCHEMA.json
16
17# install only prod deps
18RUN npm --quiet set progress=false \
19 && npm install --only=prod --no-optional \
20 && echo "Installed NPM packages:" \
21 && (npm list --only=prod --no-optional --all || true) \
22 && echo "Node.js version:" \
23 && node --version \
24 && echo "NPM version:" \
25 && npm --version
26
27# run compiled code
28CMD npm run start:prod
.gitignore
1apify_storage
2node_modules
3.idea
4dist
INPUT_SCHEMA.json
1{
2 "title": "Input schema for the hello_word actor.",
3 "type": "object",
4 "schemaVersion": 1,
5 "properties": {
6 "message": {
7 "title": "Message",
8 "type": "string",
9 "description": "Just enter your hello world message.",
10 "editor": "textfield"
11 }
12 },
13 "required": []
14}
apify.json
1{
2 "env": { "npm_config_loglevel": "silent" }
3}
package.json
1{
2 "name": "example-typescript",
3 "version": "0.0.1",
4 "description": "This is an example of an Apify actor.",
5 "dependencies": {
6 "@apify/log": "^2.1.1",
7 "apify": "^3.0.1"
8 },
9 "devDependencies": {
10 "@apify/eslint-config-ts": "^0.2.3",
11 "@apify/tsconfig": "^0.1.0",
12 "@typescript-eslint/eslint-plugin": "^5.30.7",
13 "@typescript-eslint/parser": "^5.30.7",
14 "eslint": "^8.20.0",
15 "ts-node": "^10.9.1",
16 "typescript": "^4.7.4"
17 },
18 "scripts": {
19 "start": "npm run start:dev",
20 "start:prod": "node dist/main.js",
21 "start:dev": "ts-node -T src/main.ts",
22 "build": "tsc",
23 "lint": "eslint ./src --ext .js,.ts",
24 "lint:fix": "eslint ./src --ext .js,.ts --fix",
25 "test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1"
26 },
27 "author": "It's not you it's me",
28 "license": "ISC"
29}
tsconfig.eslint.json
1{
2 "include": ["src"]
3}
tsconfig.json
1{
2 "extends": "@apify/tsconfig",
3 "compilerOptions": {
4 "skipLibCheck": true,
5 "outDir": "dist"
6 },
7 "include": [
8 "./src/**/*"
9 ]
10}
src/main.ts
1// This is the main Node.js source code file of your actor.
2// It is referenced from the "scripts" section of the package.json file,
3// so that it can be started by running "npm start".
4
5// Include Apify SDK. For more information, see https://sdk.apify.com/
6import { Actor } from 'apify';
7import log from '@apify/log';
8
9interface Schema {
10 message?: string;
11}
12
13Actor.main(async () => {
14 // Get input of the actor.
15 // If you'd like to have your input checked and have Apify display
16 // a user interface for it, add INPUT_SCHEMA.json file to your actor.
17 // For more information, see https://apify.com/docs/actor/input-schema
18
19 const input = await Actor.getInput<Schema>();
20 log.info('Input:', input);
21
22 // Do something useful here...
23 if (input?.message) {
24 log.info(`Message is: ${input.message}`);
25 }
26
27 // Save output
28 const output = {
29 receivedInput: input,
30 message: 'Hello sir!',
31 };
32 log.info('Output:', output);
33 await Actor.setValue('OUTPUT', output);
34});