Code Monkey home page Code Monkey logo

jsynowiec / node-typescript-boilerplate Goto Github PK

View Code? Open in Web Editor NEW
2.6K 38.0 515.0 993 KB

Minimalistic project template to jump start a Node.js back-end application in TypeScript. ESLint, Jest and type definitions included.

License: Apache License 2.0

TypeScript 84.29% JavaScript 15.71%
typescript nodejs boilerplate project-template jest starter-template back-end serverless backend service javascript express prettier eslint microservices node-typescript-boilerplate node-js nodejs-server typescript-boilerplate es-modules

node-typescript-boilerplate's Introduction

node-typescript-boilerplate

Sponsor TypeScript version Node.js version APLv2 Build Status - GitHub Actions

πŸ‘©πŸ»β€πŸ’» Developer Ready: A comprehensive template. Works out of the box for most Node.js projects.

πŸƒπŸ½ Instant Value: All basic tools included and configured:

  • TypeScript 5.4
  • ESM
  • ESLint with some initial rules recommendation
  • Jest for fast unit testing and code coverage
  • Type definitions for Node.js and Jest
  • Prettier to enforce consistent code style
  • NPM scripts for common operations
  • EditorConfig for consistent coding style
  • Reproducible environments thanks to Volta
  • Example configuration for GitHub Actions
  • Simple example of TypeScript code and unit test

🀲 Free as in speech: available under the APLv2 license.

Getting Started

This project is intended to be used with the latest Active LTS release of Node.js.

Use as a repository template

To start, just click the Use template link (or the green button). Start adding your code in the src and unit tests in the __tests__ directories.

Clone repository

To clone the repository, use the following commands:

git clone https://github.com/jsynowiec/node-typescript-boilerplate
cd node-typescript-boilerplate
npm install

Download latest release

Download and unzip the current main branch or one of the tags:

wget https://github.com/jsynowiec/node-typescript-boilerplate/archive/main.zip -O node-typescript-boilerplate.zip
unzip node-typescript-boilerplate.zip && rm node-typescript-boilerplate.zip

Available Scripts

  • clean - remove coverage data, Jest cache and transpiled files,
  • prebuild - lint source files and tests before building,
  • build - transpile TypeScript to ES6,
  • build:watch - interactive watch mode to automatically transpile source files,
  • lint - lint source files and tests,
  • prettier - reformat files,
  • test - run tests,
  • test:watch - interactive watch mode to automatically re-run tests

Additional Information

Why include Volta

Volta’s toolchain always keeps track of where you are, it makes sure the tools you use always respect the settings of the project you’re working on. This means you don’t have to worry about changing the state of your installed software when switching between projects. For example, it's used by engineers at LinkedIn to standardize tools and have reproducible development environments.

I recommend to install Volta and use it to manage your project's toolchain.

ES Modules

This template uses native ESM. Make sure to read this, and this first.

If your project requires CommonJS, you will have to convert to ESM.

Please do not open issues for questions regarding CommonJS or ESM on this repo.

Backers & Sponsors

Support this project by becoming a sponsor.

License

Licensed under the APLv2. See the LICENSE file for details.

node-typescript-boilerplate's People

Contributors

amitport avatar atefbb avatar dependabot[bot] avatar jbelelieu avatar jsynowiec avatar phra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-typescript-boilerplate's Issues

Jest issue

When I use the boilerplate and try and add and import statement it throws an error in jest

SyntaxError: Cannot use import statement outside a module

Screen Shot 2022-04-03 at 3 13 14 PM

Remove tsutils

Hello there.

I noticed that your project contains tsutils; this library hasn't been maintained for a year now, creating problems to others libraries like typescript-eslint.

Check this discussion link here and evaluate to remove it and clean your NPM dependencies.

Best regards and thanks for your work.

Documentation: index.d.ts

It could be good to have an index.d.ts file in the root to work in your project and you can use on the fly

Live reloading

First I just want to thank you for providing this kind of work. I am pretty new in typescript and I am practising in the environment. I just wanted to make things work like in vanilla javascript that's why I used nodemon for live reloading. There are build commands which compile typescript to javascript in npm scripts but are there any option for vscode to run compiled program in development server. I used
npm run build:watch in the first terminal and in second one nodemon /build/src/main.js it is working but I just want to be sure is that the way you are working or are there any downside of this approach, thanks.

Import file without .js extension

Thanks for creating this great template to help save tons of time configuring node typescript.

In the test code, the import statement contains the .js extension import { Delays, greeter } from '../src/main.js';, is there a way to get rid of the extension and make it simply import { Delays, greeter } from '../src/main';?

What is `tsutils` ?

I see that the package.json includes tsutils as a dev dependency, but even after reading the module's README, I have no idea what is does.

And since I don't see it being used / imported anywhere in the project, I've been wondering what it was used for ?

wrong paths in the build

When I'm trying to work with path package and access some files in the main.ts file it doesn't build well. In the build paths are related to the build/main.js file. But files are in the src directory. I'm new in the node.js, I can't find solution on the Internet. Sorry for the stupif question

fix setTimeout call

hi,

i'm quite sure that you made a typo in setTimeout call in main.ts.
i'm sending a PR to fix that.

vscode configuration

Hi,
Can you add your vscode settings and launch to git? Do you have a debug and tests - debug configurations you can share ?
Great repo!

Misleading ESLint error suppression comment

Hi there,

In main.ts, starting on L26, there is the following comment:

// Below are examples of using ESLint errors suppression
// Here it is suppressing a missing return type definition for the greeter function.

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types

I was really confused because after removing the comment, VSCode didn't raise an error in the line containing the function signature. I looked into .eslintrc.json and found the corresponding ESLint plugin defined and also 2 extensions from that plugin, leading me to assume that the rule (explicit-module-boundary-types) was already activated, especially considering the fact that you use it as an example in your boilerplate code. After explicitly activating the rule via the rules field, it started working as intended.

I think it would more sense to use a different, i.e. activated-out-of-the-box, rule as an example for ESLint error suppression examples.

npm run lint doesn't work on windows

When running on Windows I found two problems with tslint, with pretty easy fixes:

  1. single quotes can't be used

Easy fix in package.json:
BEFORE:

"lint": "tslint -t stylish --type-check --project 'tsconfig.json'",

AFTER:

"lint": "tslint -t stylish --type-check --project \"tsconfig.json\"",
  1. CRLF causing linting errors

Easy fix in tslint.json
ADD:

"linebreak-style": false

Sigh, windows...

Use Yarn

I love your project, but it would be great if we could use Yarn since it's faster for dependency management.

Running npm run test hangs

It seems that jest is hanging for some reason on the current version of the repo.

I am using node v10.15.3 and npm 6.4.1

Error when using your boilerplate

When I delete all example code I'm getting the following error:

Cannot read tslint configuration - 'Failed to load d:\Coding\management-pannel\tslint.json: Invalid "extends" configuration value - could not require "tslint-microsoft-contrib/recommended". Review the Node lookup algorithm (https://nodejs.org/api/modules.html#modules_all_together) for the approximate method TSLint uses to find the referenced configuration file.'tslint(1)

Is this only on my side or is there sth. broken?

//Edit: Even with the vanilla boilerplate I'm getting this error

tsconfig lib option and node-fetch

What is the purpose of

"lib": ["ES2022"],

in the tsconfig file?


If it isn't needed can it be removed as it seems to cause the following build errors with node-fetch:

node_modules/fetch-blob/from.d.ts:20:64 - error TS2749: 'File' refers to a value, but is being used as a type here. Did you mean 'typeof File'?

20 export function fileFrom(path: string, type?: string): Promise<File>;
                                                                  ~~~~

node_modules/fetch-blob/from.d.ts:25:60 - error TS2749: 'File' refers to a value, but is being used as a type here. Did you mean 'typeof File'?

25 export function fileFromSync(path: string, type?: string): File;
                                                              ~~~~

node_modules/formdata-polyfill/esm.min.d.ts:2:11 - error TS2749: 'FormData' refers to a value, but is being used as a type here. Did you mean 'typeof FormData'?

2   new (): FormData;
            ~~~~~~~~

node_modules/formdata-polyfill/esm.min.d.ts:3:14 - error TS2749: 'FormData' refers to a value, but is being used as a type here. Did you mean 'typeof FormData'?

3   prototype: FormData;
               ~~~~~~~~

node_modules/formdata-polyfill/esm.min.d.ts:5:50 - error TS2749: 'FormData' refers to a value, but is being used as a type here. Did you mean 'typeof FormData'?

5 export declare function formDataToBlob(formData: FormData): Blob;
                                                   ~~~~~~~~

node_modules/node-fetch/@types/index.d.ts:124:4 - error TS2749: 'FormData' refers to a value, but is being used as a type here. Did you mean 'typeof FormData'?

124  | FormData
       ~~~~~~~~

node_modules/node-fetch/@types/index.d.ts:137:22 - error TS2749: 'FormData' refers to a value, but is being used as a type here. Did you mean 'typeof FormData'?

137  formData(): Promise<FormData>;
                         ~~~~~~~~


Found 7 errors in 3 files.

Errors  Files
     2  node_modules/fetch-blob/from.d.ts:20
     3  node_modules/formdata-polyfill/esm.min.d.ts:2
     2  node_modules/node-fetch/@types/index.d.ts:124
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: `tsc -p tsconfig.json`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.