alterna-contract-api
v2.0.1
Published
API for Alterna's contracts information.
Downloads
1
Readme
nodejs-boilerplate
This is a repository boilerplate for creating a NodeJS Alterna API. Currently is using git instead of npm as registry. It gives you a template with basic folder structure and test/eslit dependencies ready.
Using the boilerplate
These are the steps you need to follow for using this boilerplate:
- Create your new repository
- Clone this repository
- Move to this repository and run these commands:
- rm -rf .git
- git init
- git remote add origin [email protected]:flipenergia/your-new-and-fresh-repo.git
- git pull origin master
- git add .
- git commit -m "initial commit"
- git push -ff --set-upstream origin master
Once you have done these steps you can also rename the name of the directory containing the new repository: mv nodejs-boilerplate-api your-new-and-fresh-repo
. Also is a good idea to update the package.json with all the properties related to the repository and the package as:
- name
- version (start with 0.0.1 is useful for prototyping)
- description
- repository.url
- author
- homepage
Deploying a version
Once you want to deploy a version you need to:
- Commit all your changes
- Increase the package version at package.json following semantic versioning
- Commit this change with the version prefixed with v as commit message. For version 1.0.0:
git commit -m "v1.0.0"
- Run
npm run tag
at the root of the project.
Using the library
Let's say you are going to use the package [email protected]
in one of your projects. You need to copy the repository url for being imported through ssh and also being sure that the machine where you are going to import it has also the ssh key enabled in alterna-log
repository.
Once you have all that sorted out you just need to run:
# You can also install it as dev dependency with npm install -D
npm install "git+ssh://[email protected]/flipenergia/alterna-log.git#v1.0.0"
The next time you deploy a new version for the library you just need to update the dependency version in the package.json and run npm run update alterna-log
.
Scripts
- lint: Executes the linter for the project following the config using ESlint.
- tag: Generates automatically the tag for git based on package.json version and pull everything to remote.
- test: Run the build script and then execute tests with Mocha and Chai.
Installation
fastify
npm i fastify --save
fastify-env plugin
Which helps you with loading environment variables and setting defaults for each variable
npm install --save fastify-env
Instructions
Execute the next command:
node index.js
Output:
Registered route: /
Registered route: /api/blogs
Registered route: /api/blogs/:id
{:30,"time":1620383671607,"pid":20155,"hostname":"artemisa","msg":"Server listening at http://127.0.0.1:40235"}
{"level":30,"time":1620383671608,"pid":20155,"hostname":"artemisa","msg":"Server listening on http://127.0.0.1:40235"}
Test the following calls in the browser (look at the port that has been opened on the server):
- http://localhost:40235
- http://localhost:40235/api/blogs
- http://localhost:40235/api/blogs/1
- http://localhost:40235/api/blogs/2
- http://localhost:40235/api/blogs/3
TO DO
- Add integration with documentación of swagger
- It always set the same port
- Testing post, put, delete methods
- Include mocha or jest tests to validate defined methods