Node.js Tutorial for Beginners
1. What is Node
- Great for prototyping and agile development
- Superfast and highly scalable
- Javascript everywhere
- Cleaner and more consistent codebase
- Large ecosystem of open-source libs
2. Node Architecture
it's a runtime environment for executing javascript code.
3. How Node Works
-
non-blocking or asynchronous
-
blocking or synchronous
Node applications are asynchronous by default.
Node is ideal for I/O-intensive apps.
Do not use Node for CPU-intensive apps.
4. Installing Node
5. Your First Node Program
function sayHello(name) {
console.log('Hello '+name);
}
sayHello('Karam');
[실행결과] # node app.js
Hello Karam
6. Node Module System
- os(operating system)
- fs(file system)
- events
- http
7. Global Object
// global.변수명
global.setTimeout()
global.clearTimeout();
global.setInterval();
global.clearInterval();
8. Modules
// app.js
console.log(module);
[실행결과] # node app.js
Module {
id: '.',
path: 'C:\\workspace\\first-app',
exports: {},
parent: null,
filename: 'C:\\workspace\\first-app\\app.js',
loaded: false,
children: [],
paths: [
'C:\\workspace\\first-app\\node_modules',
'C:\\workspace\\node_modules',
'C:\\node_modules'
]
}
9.Creating a Module
// logger.js
var url = 'http://mylogger.io.log';
function log(message){
// Send an HTTP request
console.log('hello, log message is ' + message);
}
module.exports.log = log;
10. Loading a Module
//app.js
var logger = require('./logger');
console.log(logger);
logger.log('message');
[실행결과] # node app.js
{ log: [Function: log] }
hello, log message is message
export a single function or an object
// logger.js
var url = 'http://mylogger.io.log';
function log(message){
// Send an HTTP request
console.log('hello, log message is ' + message);
}
module.exports = log;
// app.js
const log = require('./logger'); // var가 아닌 const를 사용하는 이유: 변수의 재할당을 막기 위해서
log('message');
[실행결과] # node app.js
hello, log message is message
추후 업데이트 예정
11. Module Wrapper Function
12. Path Module
13. OS Module
14. File System Module
15. Events Module
16. Event Arguments
17. Extending EventEmitter
18. HTTP Module
참고사항
Node.js Tutorial for Beginners: Learn Node in 1 Hour
Author And Source
이 문제에 관하여(Node.js Tutorial for Beginners), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@krhong/Node.js-Tutorial-for-Beginners저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)