Totally surprised when I saw the search results for the key words: 'node and rest api in 5 minutes'
Building Rest API with LoopBack: Mind blowing, read this article: https://www.freecodecamp.org/news/build-restful-api-with-authentication-under-5-minutes-using-loopback-by-expressjs-no-programming-31231b8472ca/
About Loopback:
https://auth0.com/blog/developing-restful-apis-with-loopback/
https://www.npmjs.com/package/loopback
https://loopback.io/doc/en/lb4/express-with-lb4-rest-tutorial.html
Using Fastify:
https://medium.com/zero-equals-false/build-rest-apis-in-5-minutes-with-node-js-and-fastify-5c72b67e2cd3
Just nodeJS:
https://www.codementor.io/@olatundegaruba/nodejs-restful-apis-in-10-minutes-q0sgsfhbd
Wednesday, April 22, 2020
Saturday, April 18, 2020
ES6 Super quick reference
Arrow functions:
// ES5 function sayHello (name) { return 'Hello ' + name } // ES6 const sayHello = (name) => 'Hello ' + name console.log(sayHello('Ramesh'))
Variables:
var firstName = 'Ramesh'; // ES5 let firstName = 'Ramesh' // ES6 - have block scope const firstName = 'Ramesh' // ES6 - as it says, it's a constant
Template Strings:
let strWelcome = 'Welcome'
// use the backticks to combine strings with variableslet templateString = `${strWelcome} Ramesh` console.log(templateString)
async await:
https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_awaitDestructuring:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignmentShorthand objects
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializerFunction arguments
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/argumentsExpand arrays
https://www.smashingmagazine.com/2016/07/how-to-use-arguments-and-parameters-in-ecmascript-6/let myArray = [1,2,3] Math.max(...myArray)
Classes
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/classnvm - switch node versions with nvm
Node Version Manager (nvm) helps to switch between different versions of nodejs. This article provides all the details on nvm:
Some basic commands:
https://michael-kuehnel.de/node.js/2015/09/08/using-vm-to-switch-node-versions.html
https://www.kulik.io/2019/05/01/set-default-node-version-using-nvm/
https://nodesource.com/blog/installing-node-js-tutorial-using-nvm-on-mac-os-x-and-ubuntu/
Some basic commands:
- To install nvm on mac: brew install nvm
- To install nodejs using nvm: nvm install node
- To install a specific version of nodejs: nvm install 13.5.0
- To use a specific version as default: nvm alias default 12.16.1
- To see what versions are available on your local: nvm list
- To use a specific version: nvm use <version number>
https://michael-kuehnel.de/node.js/2015/09/08/using-vm-to-switch-node-versions.html
https://www.kulik.io/2019/05/01/set-default-node-version-using-nvm/
https://nodesource.com/blog/installing-node-js-tutorial-using-nvm-on-mac-os-x-and-ubuntu/
npx - Installation-less command execution
You don't want to install some command but you want to use it on the fly! Well, npx comes to your rescue: https://nodejs.dev/the-npx-nodejs-package-runner
For a quick understanding of differences between npm and npx, read this: https://stackoverflow.com/questions/50605219/difference-between-npx-and-npm
Also read the interesting facts about Node.js: https://nodejs.dev/a-brief-history-of-nodejs
Also read the interesting facts about Node.js: https://nodejs.dev/a-brief-history-of-nodejs
Read thru this article that would help better understand an executable global module: https://medium.com/jspoint/creating-cli-executable-global-npm-module-5ef734febe32
Thursday, April 16, 2020
About JavaScript modules, module formats, module loaders, module builders
This article was written in 2017 and I was NOT blessed to read this till now. Well, better late than nothing. You want to know the intricacies of JavaScript modules, this is it, you have to read this.
Here is the link to the article: https://www.jvandemo.com/a-10-minute-primer-to-javascript-modules-module-formats-module-loaders-and-module-bundlers/
And then follow this article: https://www.sitepoint.com/understanding-module-exports-exports-node-js/, that explains the additional details of how to use nodeJS modules.
Here is the link to the article: https://www.jvandemo.com/a-10-minute-primer-to-javascript-modules-module-formats-module-loaders-and-module-bundlers/
And then follow this article: https://www.sitepoint.com/understanding-module-exports-exports-node-js/, that explains the additional details of how to use nodeJS modules.
Monday, April 13, 2020
To understand module exports
As the article header says, it was a good effort by the author to help the readers to understand Node.js module exports:
https://stackify.com/node-js-module-exports/
https://stackify.com/node-js-module-exports/
Saturday, April 11, 2020
SAS Practice Examples
Create a Student table with studentnum, quarter, math, science, english marks?
data Student; input studentnum $ quarter math science english; datalines; 1001 1 70 80 76 1001 2 80 80 78 1001 3 90 85 80 ; run;
Add 4th quarter marks as a new record and create a new Student_1 table?
data Student_1; set Student end=eof; output; if eof then do; studentnum = '1001'; quarter = 4; math = 88; science = 90; english = 88; output; end; run;
Add the total for each quarter?
data Student_marks_total; set Student_1; total = math + science + english; run;
Add the average for each column including the total as a new row in the bottom?
data Student_marks_avg; set Student_marks_total end=eof; drop sum_math sum_science sum_english sum_total; retain sum_math sum_science sum_english sum_total 0; sum_math = sum_math + math; sum_science = sum_science + science; sum_english = sum_english + english; sum_total = sum_total + total; output; if eof then do; studentnum = 'avg'; quarter = .; math = sum_math / 4; science = sum_science / 4; english = sum_english / 4; total = sum_total / 4; output; end; run;
Sort the Student_1 table by reversing the quarter?
proc sort data=student_1 out=student_1_sort_by_quarter; by descending quarter; run;
Combine Sales, Delivery employee datasets as Marketing dataset?
data Sales; input empno empname $; datalines; 1001 Daniel 1002 Peter ; run; data Delivery; input empno empname $; datalines; 1003 Simon 1004 Chris ; run; data Marketing; set Sales Delivery; run;
Merge a Student's arts and groups marks into a single dataset?
data student_arts; input studentnum english spanish latin; datalines; 1001 80 70 78 ; run; data student_groups; input studentnum math science history; datalines; 1001 88 78 89 ; run; data student_arts_and_groups; merge student_arts student_groups; by studentnum; run;
Is it possible to create a table in a simple way with couple of records and couple of columns?
data blah; firstname = 'Sean'; lastname = 'Connery'; run;
Or with two records
data blah; firstname = 'Sean'; lastname = 'Connery'; output; firstname = 'Matt'; lastname = 'Damon'; output; run;
Calculate average and grade the student based on this grading guidelines?
failed: below 35
ordinary: > 35 and <= 50
second: > 50 and <= 60
first: > 60 and <= 70
distinction: > 70
data Student; input studentnum $ math science english; datalines; 1001 40 50 46 1002 60 60 68 1003 90 85 80 1004 10 20 23 ; run; data Student_grading; set Student; average = (math + science + english) / 3; average = Round(average, 0.01); length grading $ 12; if average > 35 and average <= 50 then grading = 'ordinary'; else if average > 50 and average <= 60 then grading = 'second'; else if average > 60 and average <= 70 then grading = 'first'; else if average > 70 then grading = 'distinction'; else grading = 'failed'; run;
Based on Student marks, decide the grading and add some comments?
(NOTE: more than one action in if-then statement, so you have to use do)
data student; input studentnum marks; datalines; 1001 49 1002 89 1003 34 1004 89 ; run; data student_report; set student; if marks > 50 then do; result = 'pass'; comments = 'eligible to go to next level'; end; else do; result = 'fail'; comments = 'not eligible to next level'; end; run;
How to add a column with table name?
data report_card; set student_grading indsname=name; tablename=scan(name,2); run;
Create a temp dataset out of Student dataset using SQL?
proc sql; create table student_temp as select * from student; quit;
Add numbers 1 to 5 and give the sum?
data sum_1_to_5; sum = 0; do i = 1 to 5; sum = sum + i; end; drop i; run;
Nik has 10 dollars. Vik has 16 dollars. Keep giving Nik a dollar per day till they both have equal money?
(Note: Use Do while loop)
data level_the_brothers; nik_money = 10; vik_money = 16; do while (nik_money < vik_money); nik_money = nik_money + 1; end; final_nik_money = nik_money; final_vik_money = vik_money; drop nik_money vik_money; run;
Nik has 10 dollars. Vik has 16 dollars. Keep giving Nik a dollar per day till they both have equal money?
(Note: Use Do until loop)
data level_the_brothers; nik_money = 10; vik_money = 16; do until (nik_money = vik_money); nik_money = nik_money + 1; end; final_nik_money = nik_money; final_vik_money = vik_money; drop nik_money vik_money; run;
Find the total, average marks of students if all 6 subjects marks are provided for each student?
data array_example; input studentnum s1 s2 s3 s4 s5 s6; array s(6) s1-s6; /* Hint - array element names match column names */ marks_total = sum(of s(*)); marks_avg = round(mean(of s(*)), 0.01); datalines; 1001 78 56 45 34 75 65 1002 56 67 78 89 45 34 ; run;
Subscribe to:
Posts (Atom)