티스토리 뷰

- node.js 설치

- vscode 설치

- express 설치

 

exporess라는 라이브러리를 사용해서 서버를 만듦

 

express 라이브러리 설치

1. vscode에서 터미널 열기

2. npm init 입력해서 세팅하기

*npm: 라이브러리 설치를 도와주는 도구

 

어떤 라이브러리를 설치했는지 기록: package.json

 

entry point에 server.js 입력

 

npm install express

(yarn add express)

 

 

기본 세팅

const express = require('express');
const app =express();

app.listen(8080, function(){ // listen(서버 띄울 포트번호, 띄운 후 실행할 코드)
    console.log('listening on 8080')
}); // 서버를 띄우기 위한 기본 세팅

 

 

nodemon으로 자동화

npm install -g nodemon

 

nodemon으로 서버 실행

nodemon server.js

 

* powershell 보안 오류로 서버 실행 안될 때

더보기

관리자 권한으로 powershell 실행

executionpolicy

- Restricted라고 뜨면 허가하지 않은 스크립트라 막히는 것

 

실행 규칙 변경 하기

set-executionpolicy unrestricted

y 입력

 

 

 

body-parser

: 폼에 입력한 데이터를 쉽게 사용하기 위한 라이브러리

npm install body-parser

기본 세팅 해준 곳에 같이 선언해두기

 

<server.js>

const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended : true}));

 

 

 

 

'Server > Node.js' 카테고리의 다른 글

[Node.js] AJAX로 삭제 요청하기  (0) 2023.07.15
[Node.js] auto increment; 글 번호를 달자  (0) 2023.07.14
[Node.js] MongoDB 세팅  (0) 2023.07.13
[Node.js] REST API  (0) 2023.07.12
[Node.js] Node.js란?  (0) 2023.07.12
댓글