-
Notifications
You must be signed in to change notification settings - Fork 0
NodeJS
$ npm install express --save
$ npm install body-parser --save
$ npm install cookie-parser --save
$ npm install multer --save
How simple Node.js is ?
var express = require('express');
var app = express();
var fs = require("fs");
app.get('/listUsers', function (req, res) {
fs.readFile( __dirname + "/" + "users.json", 'utf8', function (err, data) {
console.log( data );
res.end( data );
});
})
var server = app.listen(8081, function () {
var host = server.address().address
var port = server.address().port
console.log("Example app listening at http://%s:%s", host, port)
})
Version Checking
node -v
npm -version
nvm (node version manager) is a CLI to install different version of NodeJS
npm (node package manager) is a CLI for managing the node modues
- callback - callbacks youtell the executing function what to do when the asynchronous task completes
- promise - with promises the executing function returns a special object to you (the promise) and then you tell the promise what to do when the asynchronous task completes
- observable - it's data stream…
const promise = asyncFunc(function(resolve, reject) {.... });
promise.then(result => {
console.log(result);
});
const hello = Observable.create(function(observer) {
observer.next('Hello');
observer.next('World');
});
const subscribe = hello.subscribe(val => console.log(val));
let Observable = Rx.Observable
let resultA, resultB, resultC
function addAsync (num1, num2) {
const promise = fetch(`http://example.com?num1=${num1}&num2=${num2}`)
.then(x => x.json())
return Observable.fromPromise(promise)
}
addAsync(1, 2)
.do(x => resultA = x)
.flatMap(x => addAsync(x, 3))
.do(x => resultB = x)
.flatMap(x => addAsync(x, 4))
.do(x => resultC = x)
.subscribe(x => {
console.log('total', x)
conosle.log(resultA, resultB, resultC)
})
babel-node
https://wohugb.gitbooks.io/ecmascript-6/docs/class.html
import {xxx, yyy} from './abc'
in abc file, export class xxx
export function yyy
import * as abc from './abc'
abc.xxx
abc.yyy()
import {xxx as a} from './abc'
https://www.howtoing.com/install-pm2-to-run-nodejs-apps-on-linux-server
https://morning.work/page/2014-08/deploy-nodejs-production-app.html
https://code.kpman.cc/2015/09/12/%E5%BE%9Edeploy-node-js-%E5%B0%88%E6%A1%88%E6%89%80%E5%AD%B8/
Basic Tutorial
https://www.javatpoint.com/what-is-nodejs
Setup Environment
Middleware Concept
Body Parser
https://github.com/expressjs/body-parser
Promise
https://itnext.io/javascript-promises-vs-rxjs-observables-de5309583ca2
https://medium.com/dev-bits/writing-neat-asynchronous-node-js-code-with-promises-32ed3a4fd098
https://andyyou.github.io/2017/06/27/js-promise/
Node in Production
https://www.pluralsight.com/tech-blog/running-nodejs-in-production
Node Express TypeScript API Tutorial
https://developer.okta.com/blog/2018/11/15/node-express-typescript
NodeJS API Backend + JWT + Angular Front End
https://www.toptal.com/angular/angular-6-jwt-authentication
https://github.com/quantificial/demo-node-simple
Express Boilerplate
https://github.com/w3tecch/express-typescript-boilerplate
Simple Restful Web Services
https://www.tutorialspoint.com/nodejs/nodejs_restful_api.htm
Securing Nodejs restful api
https://medium.freecodecamp.org/securing-node-js-restful-apis-with-json-web-tokens-9f811a92bb52
- freemarker
- thymeleaf
- JMX (jconsole)
- ZeroMQ
- microk8s
- multipass
- pwsh (powershell)