Node.JS Examples:
To help get you started, we've included some example basic Node.JS script examples that you can use with the Server CLI.
Github
There are examples in the Github repo, and you can find them in the "examples" folder:
https://github.com/blinkmobile/server-cli/tree/master/examples/directory
Here you'll find a basic "helloworld" script, plus a promise based script that simulates a longer server script execution time.
Download ZIP
If you prefer, you can download the examples here, directly:
Quick Javascript Tips and Suggestions:
Maintainability, Sustainability
When designing your Javascript code, for longer-term maintainability and sustainability, consider:
Extract shared logic out into separate files, and use a module system so that you can
require()
as neededKeep credentials and other environment variables out of your code. See dotenv or similar approaches
Consider keeping integration functions (e.g. network requests, libraries) separate from processing functions (e.g. transformations, data traversal) in order to make them easier to test
Consider writing automated tests with one of the following test frameworks or similar: ava, jest, mocha, tape
Convenient HTTP Requests
Here are our favourite ways of making HTTP requests with JavaScript:
- Browser:
fetch()
(built-in) Node.js: node-fetch (like browsers'
fetch()
)