$ npm install$ npm start# Watch mode
$ npm run dev
# Lint
$ npm run lint
$ npm run lint:watch
# Type check
$ npm run type
$ npm run type:watch| package-lock.json | |
| node_modules/** | |
| .editorconfig | |
| .eslintrc.yaml | |
| .prettierrc.json | |
| data/** | |
| *.js |
| import { getEnvVar } from "./utils"; | |
| const main = async () => { | |
| console.log(`HOME: ${getEnvVar("HOME")}`); | |
| }; | |
| console.log("### BEGIN ###\n"); | |
| main() | |
| .then(() => console.log("\n### FINISH ###")) | |
| .catch((err) => console.error(`\n### ERROR: ${err}`)); |
| { | |
| "name": "nodejs-script", | |
| "author": "mryhryki", | |
| "private": true, | |
| "license": "MIT", | |
| "engines": { | |
| "node": "18.x", | |
| "npm": "9.x" | |
| }, | |
| "scripts": { | |
| "start": "esbuild --platform=node18 --external:node:* --bundle --minify ./index.ts | node", | |
| "dev": "nodemon --watch ./ --ext ts --exec 'npm start'", | |
| "lint": "mryhryki-lint", | |
| "lint:fix": "mryhryki-lint-fix", | |
| "type": "tsc", | |
| "type:watch": "tsc --watch" | |
| }, | |
| "dependencies": { | |
| "@mryhryki/lint": "^0.0.12", | |
| "@types/node": "^18.11.17", | |
| "@types/node-fetch": "^3.0.3", | |
| "esbuild": "^0.16.10", | |
| "node-fetch": "^3.3.0", | |
| "nodemon": "^2.0.20", | |
| "typescript": "^4.9.4" | |
| }, | |
| "nodemonConfig": { | |
| "delay": 1000 | |
| } | |
| } |
| { | |
| "compilerOptions": { | |
| "allowJs": false, | |
| "allowSyntheticDefaultImports": true, | |
| "esModuleInterop": true, | |
| "jsx": "preserve", | |
| "lib": ["esnext", "DOM.Iterable", "dom"], | |
| "noEmit": true, | |
| "noImplicitAny": true, | |
| "skipLibCheck": true, | |
| "strict": true | |
| }, | |
| "include": [ | |
| "*.ts" | |
| ], | |
| "exclude": [ | |
| "**/node_modules/**", | |
| "**/*.test.ts" | |
| ] | |
| } |
| export const getEnvVar = (name: string): string => { | |
| const value = process.env[name]; | |
| if (!value) throw new Error(`Missing environment variable ${name}`); | |
| return value; | |
| }; |