티스토리 뷰
반응형
import dgram from 'dgram';
import { Buffer } from 'buffer';
const message = Buffer.from('helloworld');
const client = dgram.createSocket('udp4');
client.send(message, 5555, 'localhost', (err) => {
client.close();
});
[node/js] node환경에서 import 쓰기(es6)
#package.js에 'type':'module' 추가를 하면된다.
#pakage.js
{
"name": "node",
"version": "1.0.0",
"main": "test.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"description": ""
}
#client.js
import dgram from 'dgram';
import { Buffer } from 'buffer';
const message = Buffer.from('helloworld');
const client = dgram.createSocket('udp4');
client.send(message, 5555, 'localhost', (err) => {
client.close();
});
import가 오류 없이 정상 이용된다.
#javascript #js #import #module #types #node #es6
반응형
'자바스크립트(javascript)' 카테고리의 다른 글
[javascript/node/typescript]log및 string 동적으로 효율적으로 쓰기 (0) | 2021.12.11 |
---|---|
[node/js] node에서 간단한 udp server / client 구현 (0) | 2021.12.11 |
[nestjs/typeorm]typeormmodule unable to connect to the database queryfailerror null column 오류 발생 시 column추가하여 실행 시 오류 (0) | 2021.11.22 |
[nodejs(노드)/npm] 설치 (0) | 2021.11.12 |
[node(노드)/express(익스프레스)] 1분만에 API 서버 만들기 (0) | 2021.11.11 |
댓글
반응형