Node.js Development

Stack

  • TypeScript
  • Express - web api
  • Winston - logger

Language features:

  • ES6
  • Promises

Project structure

TypeScript based project

.
|-- src
|   |-- config
|   |-- public
|       |-- feature-1
|       |-- feature-2
|       |-- feature-3
|-- test
|-- views
|-- package.json

example

Pure js based project

.
|-- config
|   |-- components
|   |   |-- common.js
|   |   |-- logger.js
|   |   |-- rabbitmq.js
|   |   |-- server.js
|   |-- index.js
|   |-- social-preprocessor-worker.js
|   |-- twitter-stream-worker.js
|   `-- web.js
|-- models
|   |-- redis
|   |   |-- index.js
|   |   `-- redis.js
|   |-- tortoise
|   |   |-- index.js
|   |   `-- tortoise.js
|   `-- twitter
|       |-- index.js
|       `-- twitter.js
|-- scripts
|-- test
|   `-- setup.js
|-- web
|   |-- middleware
|   |   |-- index.js
|   |   `-- parseQuery.js
|   |-- router
|   |   |-- api
|   |   |   |-- tweets
|   |   |   |   |-- get.js
|   |   |   |   |-- get.spec.js
|   |   |   |   `-- index.js
|   |   |   `-- index.js
|   |   `-- index.js
|   |-- index.js
|   `-- server.js
|-- worker
|   |-- social-preprocessor
|   |   |-- index.js
|   |   `-- worker.js
|   `-- twitter-stream
|       |-- index.js
|       `-- worker.js
|-- index.js
`-- package.json

Client & Server are both in TypeScript, one repository

Creating a MEAN Stack with Angular 2 and TypeScript

Web api

Tests

Integration testing (end-to-end) for API:

All You Need to Know About Integration Testing: SuperTest, Mocha, and Chai

Frontend applications:

Protractor for AngularJS applications or Nightwatch. To make sure it works in every browser you support, run your end-to-end tests on a Selenium cluster. Or you can use services like Sauce Labs or Browserstack.

Linting

TypeScript Linting with TSLint – Setup, Configuration, & Rules

TSLint

npm install tslint typescript -g

Rules extention with TSLint-ESLint

npm install --save-dev tslint-eslint-rules

Build

The following steps can occur:

  • installing dependencies from NPM (public or private)
  • run unit tests
  • build assets, like css and javascript
  • run integration/end-to-end tests
  • creating artifacts (bundle the node_modules directory to it as well, so during deployment, you won’t depend on NPM)

Deploy

API Documentation

Run

When port is accessed in the code as process.env.PORT you can run app with selected port using

PORT=7878 node app.js

Operating in Production