>  기사  >  웹 프론트엔드  >  Node.js 기본 지식 학습

Node.js 기본 지식 학습

小云云
小云云원래의
2018-02-27 09:14:461200검색

Javascript는 일반적으로 웹 프론트엔드 개발에 사용되었습니다. 그러나 node.js의 등장으로 인해 JavaScript를 사용한 백엔드 프로그램 개발은 더 이상 복잡한 문제가 아닙니다. node.js의 js 엔진은 chrome v8 브라우저에서 제공되며 node.js에서 개발한 추가 도구 코드를 사용하면 매우 쉽고 효율적입니다. 또한 node.js에는 pip와 같은 도구인 npm도 있습니다. npm을 사용하면 타사 소프트웨어를 쉽게 설치할 수 있어 개발 작업이 매우 편리해집니다. 주말을 활용하여 node.js를 배우는 것은 정말 좋습니다.

1. node.js를 설치합니다

sudo apt-get install nodejssudo apt-get install nodejs

2、安装npm

sudo apt-get install npm

3、尝试安装express框架

npm install express --save

4、编写最简单的hello.js,用nodejs hello.js来执行

console.log('hello world')

2. npm

sudo apt-get install npm


3. Express Framework

npm install express --save


4를 설치해 보세요. 가장 간단한 hello.js를 작성하고 nodejs hello.js를 사용하여

console.log('hello)를 실행하세요. world')

5. 더 복잡한 http 서버 코드

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
 res.statusCode = 200;
 res.setHeader('Content-Type', 'text/plain');
 res.end('Hello World\n');
});

server.listen(port, hostname, () => {
 console.log(`Server running at http://${hostname}:${port}/`);
});

6. Express를 사용하여 http 서버를 개발하세요

var express = require('express');
var app = express();
 
app.get('/', function (req, res) {
  res.send('Hello World');
})
 
var server = app.listen(8081, function () {
 
 var host = server.address().address
 var port = server.address().port
 
 console.log("access url is http://%s:%s", host, port)
 
})

7. 프레임워크에는 많은 타사 라이브러리도 포함되어 있어 사용하기가 매우 편리합니다. 관련 권장사항:


node.js 기본 모듈 http, 크롤러_node.js

🎜🎜🎜Node.js 설치 및 환경 구성 튜토리얼🎜🎜🎜🎜PHP 및 Node.js🎜🎜🎜🎜을 구현하기 위한 웹 페이지 분석 도구 cherrio 🎜

위 내용은 Node.js 기본 지식 학습의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.