Cute Happy Ghost
본문 바로가기
Front/Javascript·Jquery

20201113_35 노드생성

by JENN_tech7 2020. 11. 13.
728x90
SMALL

web이라는 하위폴더생성

 

 

web으로 이동해서 npm init해줌

PS C:\Users\wotjd\Frontend> cd 20201113
PS C:\Users\wotjd\Frontend\20201113> cd web
PS C:\Users\wotjd\Frontend\20201113\web> npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help init` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (web)
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to C:\Users\wotjd\Frontend\20201113\web\package.json:

{
  "name": "web",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}


Is this OK? (yes)
PS C:\Users\wotjd\Frontend\20201113\web> 

package.json생김

 

 

 

 

PS C:\Users\wotjd\Frontend\20201113\web> npm install express
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN web@1.0.0 No description
npm WARN web@1.0.0 No repository field.

+ express@4.17.1
added 50 packages from 37 contributors and audited 50 packages in 5.234s
found 0 vulnerabilities

node_module어쩌고 생김

 

 

static도 만들어줌

 

 

 

 

  • index.js
//express 프레임워크 임포트
const express = require("express")
const app = express() 
const PORT = 6600//포트 번호

//미들웨어 추가
app.use(express.static('./static'))

//더미 데이터
const data = {
    id : '1234',
    name : 'Chiho Won',
    myData : [1,2,3]
}
app.get('/data', (req, res) => {
    //data 객체를 json으로 서빙해줌
    //JSON: Javascript Object Notation
    res.json(data)
})



// 애플리케이션 시작!
app.listen(PORT, () => {
    console.log('애플리케이션이 시작됨.')
})

 

 

 

  • index.html
<!DOCTYPE html>
<html>
    <head>
    <title>Hello Node.js</title>
    <script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>

    </head>
    <body>
        <h1>이게되나?</h1>
    </body>
</html>

 

 

쌤이 준 주소로 들어가면

http://localhost:6600/

 

 

너무 빨라서 놓쳤음 ㅠ_ㅠ

728x90
LIST

'Front > Javascript·Jquery' 카테고리의 다른 글

화면구현TEST  (0) 2020.12.10
filter  (0) 2020.11.30
20201113_ 35 노드2  (0) 2020.11.13
20201113_ 35 클로저..  (0) 2020.11.13
20201112_ 34 기본  (0) 2020.11.12

댓글