Run from a new project folder:
curl https://gist.githubusercontent.com/eezing/6aa3b59137260916ea7fdd4040faa72a/raw/node-starter.sh | sh| #!/bin/bash | |
| # Git init | |
| git init; | |
| # Make directory | |
| mkdir "src"; | |
| mkdir "src/__tests__"; | |
| mkdir ".vscode"; | |
| # Download files | |
| curl https://gist.githubusercontent.com/eezing/6aa3b59137260916ea7fdd4040faa72a/raw/root_package.json --output package.json; | |
| curl https://gist.githubusercontent.com/eezing/6aa3b59137260916ea7fdd4040faa72a/raw/root_.eslintrc.yaml --output .eslintrc; | |
| curl https://gist.githubusercontent.com/eezing/6aa3b59137260916ea7fdd4040faa72a/raw/root_.prettierrc.yaml --output .prettierrc; | |
| curl https://gist.githubusercontent.com/eezing/6aa3b59137260916ea7fdd4040faa72a/raw/root_.prettierignore --output .prettierignore; | |
| curl https://gist.githubusercontent.com/eezing/6aa3b59137260916ea7fdd4040faa72a/raw/root_.gitignore --output .gitignore; | |
| curl https://gist.githubusercontent.com/eezing/6aa3b59137260916ea7fdd4040faa72a/raw/root_.eslintignore --output .eslintignore; | |
| curl https://gist.githubusercontent.com/eezing/6aa3b59137260916ea7fdd4040faa72a/raw/root_.vscode_launch.json --output .vscode/launch.json; | |
| curl https://gist.githubusercontent.com/eezing/6aa3b59137260916ea7fdd4040faa72a/raw/root_src_index.js --output src/index.js; | |
| curl https://gist.githubusercontent.com/eezing/6aa3b59137260916ea7fdd4040faa72a/raw/root_src___tests___test.js --output src/__tests__/test.js; | |
| # Install packages | |
| npm init -f; | |
| npm install --save-dev \ | |
| jest \ | |
| prettier \ | |
| eslint \ | |
| eslint-plugin-prettier \ | |
| eslint-config-prettier \ | |
| eslint-plugin-react \ | |
| babel-eslint \ | |
| babel-jest \ | |
| husky | |
| # Run prettier | |
| npm run pretty; | |
| # Git commit | |
| git add -A; | |
| git commit -m "initial commit" |
| node_modules | |
| coverage |
| env: | |
| browser: true | |
| commonjs: true | |
| es6: true | |
| node: true | |
| jest: true | |
| parser: babel-eslint | |
| plugins: | |
| - prettier | |
| extends: | |
| - eslint:recommended | |
| - plugin:react/recommended | |
| - prettier | |
| settings: | |
| react: | |
| version: "16.0" | |
| rules: | |
| no-console: 2 | |
| react/display-name: 0 |
| # OS | |
| .DS_Store | |
| # Logs | |
| logs | |
| *.log | |
| npm-debug.log* | |
| # Runtime data | |
| pids | |
| *.pid | |
| *.seed | |
| # Directory for instrumented libs generated by jscoverage/JSCover | |
| lib-cov | |
| # Coverage directory used by tools like istanbul | |
| coverage | |
| # nyc test coverage | |
| .nyc_output | |
| # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | |
| .grunt | |
| # node-waf configuration | |
| .lock-wscript | |
| # Compiled binary addons (http://nodejs.org/api/addons.html) | |
| build/Release | |
| # Dependency directories | |
| node_modules | |
| jspm_packages | |
| # Optional npm cache directory | |
| .npm | |
| # Optional REPL history | |
| .node_repl_history | |
| # build | |
| .build | |
| .next |
| node_modules | |
| coverage |
| semi: true | |
| bracketSpacing: true | |
| singleQuote: true | |
| jsxBracketSameLine: true |
| { | |
| "version": "0.2.0", | |
| "configurations": [ | |
| { | |
| "type": "node", | |
| "request": "attach", | |
| "name": "Node: Nodemon", | |
| "processId": "${command:PickProcess}", | |
| "restart": true, | |
| "protocol": "inspector" | |
| } | |
| ] | |
| } |
| { | |
| "scripts": { | |
| "start": "node src", | |
| "dev": "PORT=3000 nodemon --watch src ./src", | |
| "debug": "PORT=3000 nodemon --inspect --watch src ./src", | |
| "pretty": "prettier --write '**/*.js'", | |
| "test": "npm run test:jest && npm run test:lint", | |
| "test:watch": "jest --watch", | |
| "test:jest": "jest --coverage", | |
| "test:lint": "eslint ./ --ext .js --ext .mjs", | |
| "test:gitunstaged": | |
| "if ! [[ -z $(git diff) ]]; then echo \"tree has un-staged changes\"; exit 1; fi", | |
| "precommit": "npm run test:gitunstaged && npm test" | |
| }, | |
| "jest": { | |
| "testURL": "http://localhost/" | |
| } | |
| } |
| describe('describe my unit test', () => { | |
| const foo = 'bar'; | |
| test('expect foo to equal bar', () => expect(foo).toEqual('bar')); | |
| }); |
| 'use strict'; | |
| const PORT = process.env.PORT; | |
| const url = require('url'); | |
| const http = require('http'); | |
| const server = http.createServer((req, res) => { | |
| const { pathname } = url.parse(req.url); | |
| if (pathname === '/healthz') { | |
| res.statusCode = 200; | |
| res.setHeader('Content-Type', 'text/plain'); | |
| res.end('Hello, World!\n'); | |
| } else { | |
| res.statusCode = 404; | |
| res.end(); | |
| } | |
| }); | |
| server.listen(PORT, () => { | |
| console.log(`Server running at http://localhost:${PORT}`); //eslint-disable-line | |
| }); |