[nodejs] nodemon 패키지 설치 & HTML 파일 전송

2022. 7. 5. 13:52·Nojde.js
npm init

nodemon server.js

아래와 같은 오류가 생긴다. 권한이 없어서 생기는 오류

powershell에 관리자로 접속한다.

위와 같은 코드를 입력하여 제한된 권한을 풀어준다. 다시 nodemon 패키지를 설치한다.

nodemon server.js

서버에서 HTML 파일전송

// server.js

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

app.listen(8080, function(){
    console.log('listening on 8080')
});

// '/' 하나만 입력해주면 홈페이지로 연결시켜준다.
app.get('/', function(request, response){
    response.sendFile(__dirname + '/index.html')
})

index.html 파일을 불러와준다.

// index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h4>홈페이지입니다.</h4>
    <p>안녕하세요</p>
</body>
</html>

localhost:8080/ -> 입력시 index.html 파일이 나타나게 된다.

저작자표시 (새창열림)

'Nojde.js' 카테고리의 다른 글

[nodejs] REST API란 무엇인가(원칙 6가지)  (0) 2022.07.05
[nodejs] express로 GET request 받기  (1) 2022.07.05
[nodejs] nodejs & express 설치  (0) 2022.07.05
'Nojde.js' 카테고리의 다른 글
  • [nodejs] REST API란 무엇인가(원칙 6가지)
  • [nodejs] express로 GET request 받기
  • [nodejs] nodejs & express 설치
coder_
coder_
어차피 할거 즐기자
  • coder_
    Good coder
    coder_
  • 전체
    오늘
    어제
    • 분류 전체보기 (41)
      • 인공지능 [AI] (3)
      • 모의해킹 (3)
      • Git (2)
      • Cloud (4)
      • 컴퓨터 과학 [CS] (3)
      • 데이터베이스 [DB] (2)
      • Nojde.js (4)
      • Javascript (3)
      • Django (4)
      • Code up (11)
        • 코드업 기초 100제 (9)
        • 단순 반복문 (2)
      • 백준 baek_joon (1)
        • 단계별 문제풀이 (1)
      • Web Scraping (1)
  • 블로그 메뉴

    • 글쓰기
    • 관리
  • 링크

    • GitHub
  • 공지사항

  • 인기 글

  • 태그

    Bastion host
    코드업
    llama3.1
    hugging face
    node.js
    기초 100제
    GCP
    Lightsail
    ubuntu 24.04
    Linux
    Coding Test
    php
    code up
    MariaDB
    Python
    파이썬
    nodejs
    ubuntu
    기초100제
    모의해킹
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.5
coder_
[nodejs] nodemon 패키지 설치 & HTML 파일 전송
상단으로

티스토리툴바