Node Learning
I like writing with Node API, for example with this code I make support my site by years, and finally I had time to publish it to Github https://github.com/Alex-1557/Node-FindReplace. And this is description of my first huge commercial project with Node and Express.
- Developer workflow. Developer workflow mean (1)install nodemon to automatic reload server, (2) setup correct launch.json on VS Code config and (3) setup script on package.json
- Common Express pipeline. (1) define various environment constant in .env with package dotenv, (2) define route endpoint in./routes/index.js, (3) define Express and function StartServer with all parameters for Express.USE(), (4) define Error handling middleware, (5) startServer.
- add API endpoint. To add endpoint need to do 3 point - (1) add endpoint to Index.js, (2) and method to API controller and (3) add DTO object, (4) ValidateDTO function.
- Strip gateway. Strip controller has 3 method:
- MySQL Query. For working with SQL I simple add a query with "?" instead parameters and pass parameters to query. In this case I also used uid generator.
- Pack complex object (like firebase access object) with Node Buffer.From function
- Various additional protection. Define in config JWT secret key and Static protection key and check it.
- GraphQL request
- Various Axios request to 3-rd party API
1: router.post('/webhook', async function(req, res) {
2: await stripeController.stripeWebhook(req, res);
3: });
4: router.get('/getbillinginfo', validate(false), async function(req, res) {
5: await stripeController.getSubscriptionInfo(req, res);
6: });
7:
8: router.get('/cancelsubscription', validate(false), async function(req, res) {
9: await stripeController.cancelSubscription(req, res);
10: });
And now I decide to improve my skills and take lecture online from Maximilian Schwarzmüller:
1. Node.JS and Express
Comments (
)
Link to this page:
http://www.vb-net.com/NodeLearning/Index.htm
|