Skip to content

Instantly share code, notes, and snippets.

@mryhryki
Last active January 30, 2023 09:05
Show Gist options
  • Save mryhryki/f46d967e7570e4b73a102d075707b851 to your computer and use it in GitHub Desktop.
Save mryhryki/f46d967e7570e4b73a102d075707b851 to your computer and use it in GitHub Desktop.
Node.js script pack template for private use.

{{GIST_NAME}}

Setup

$ npm install

Execute

$ npm start

Development

# 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;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment