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
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
- Jest (.test.ts) - integration, api testing
-
Jasmine (.spec.ts)
- test runner: mocha, alternatively tape
- assertion library: chai, alternatively the assert module (for asserting)
- test spies, stubs and mocks: sinon (for test setup).
- Unit testing - RisingStack
- Unit testing node applications with TypeScript — using mocha and chai
- Debugging Mocha Tests Written in TypeScript with Visual Studio Code
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
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
- Setup for production
- Automating Node.js Deployments with Docker and Bamboo
- Continuous Deployment of Node.js Applications
- Package Your Node.js Application for Deployment in an Offline Environment
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