Giter VIP home page Giter VIP logo

node's Introduction

nodejs-starter

If you need to write node.js application like express app, you want to make it with Typescript, this repo can be useful for you.

What do we have here:

  • Typescript
  • Path aliases
  • Dotenv support
  • File watcher

Themes

Environment variables using .env files

Pay attention that there are support .env files using dontenv plugin, but ONLY for development mode. Why? Usually you are not using .env files on production due to security risks, but if you need this, modify you start script:

{
  ...
  "scripts": {
    ...
    "start": "npm run build && node -r dotenv/config ./build/main.js",
  }

}

How to build?

To build project use next command:

$ npm run build

How to run in watch/development mode?

To run project in watch mode, that means that it will make rebuild on every change you need to run next command:

$ npm run start:dev

We are using nodemon as a watcher, feel free to modify its config nodemon.json.

How to run in production mode?

To run project in production use next command:

$ npm run start

This command will build your project and then run it.

How to use path alias?

This sample has already path alias example.

Take a look into utils/say-hello.ts:

export const sayHello = () => {
  console.log('Hello!');
};

And how it's imported in main.ts file.

import { sayHello } from '@utils/say-hello';

To make path alias works, in main.ts file, on the very first line you should have next line:

import 'module-alias/register';

Then you need to define your aliases in both tsconfig.json and package.json files. There are some difference, in tsconfig.json you need to define path relative to your src structure.

tsconfig.json

{
  ...
  "paths": {
    "@utils/*": ["utils/*"],
  }
}

But in package.json - relative to your build folder structure

{
  ...
  "_moduleAliases": {
    "@utils": "./build/utils"
  }
}

All in all, they are the same, but in package.json you need to add "./build/" string.

node's People

Contributors

1mehdifaraji avatar

Watchers

 avatar

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.