본문 바로가기

카테고리 없음

Nodejs HTTP 서버띄우기(1)

const http = require("http");
const app = http.createServer((request, response)=>{
    response.writeHead(200,{"content-type": "text/html; charset=utf-8"});  //한글깨짐방지
    if (request.url == "/"){
        response.end("여기는 루트입니다.");
    }
    else if(request.url == "/login"){
        response.end("여기는 로그인입니다.");
    }
    //console.log(request.url);                     
});

app.listen(3001,()=>{
    console.log("http로 가동한 서버입니다.")
})

터미널에서 node apps.js 가동이 안될때 아래 링크 참고 

https://piaocanyi.tistory.com/170

 

Nodejs express 패키지 모듈 설치 / 서버 띄우기

const { response } = require("express"); const express = require("express"); //express 모듈 다운받기 const { request } = require("http"); const app = express(); //app 변수에 express 실행 app.get("/"..

piaocanyi.tistory.com