반응형

Node.js 패키지 생성 및 실행 - Node.js package, npm init, npm run 

 

 

Node.js의 패키지 만들기
 - 폴더 생성
 - 콘솔에서 생성된 폴더로 이동
 - 패키지를 생성하기 위해 npm init 명령어를 실행
 - 폴더에 package.json 파일이 생성됩니다.
D:\_nodejs\nodePjt>
D:\_nodejs\nodePjt>npm init

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



* 패키지를 설치하는 명령어입니다.
  Express.js 설치하기
  Express.js는 Node.js에서 HTTP와 관련된 컴포넌트를 기반으로 하는 웹 애플리케이션 프레임워크입니다.
  현재 패키지(애플리케이션)에 Express.js를 설치하기 위해 콘솔에서 npm install 명령어를 실행합니다.
  npm install에 옵션으로 --save를 추가하면 자동으로 package.json 파일의 "dependencies"에 "express" 항목이 추가됩니다.

D:\_nodejs\nodePjt>
D:\_nodejs\nodePjt>npm install express --save

{
  "name": "test1",
  "version": "1.0.0",
  "description": "test",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "carrotweb",
  "license": "ISC",
  "dependencies": {
    "express": "^4.17.1" --> 추가
  }
}





 * Node.js의 패키지(애플리케이션) 실행하기
 * Node.js를 종료는 콘솔에서 Ctrl + C를 누르면 됩니다.

D:\_nodejs\nodePjt>
D:\_nodejs\nodePjt>node index.js
Listening...
^C
D:\_nodejs\nodePjt>^C
D:\_nodejs\nodePjt>



=========================================================


접속 : http://localhost:8080/index.html


* npm으로 실행하기 위해 Script 추가하기
* 콘솔에서 npm start를 실행합니다.
  종료하려면 콘솔에서 Ctrl + C를 누르고 "Y"를 입력하고 엔터키를 누르면 됩니다.

D:\_nodejs\nodePjt>npm run start
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

> nodepjt@1.0.0 start
> node index.js

Listening...



* Express 정적 파일 적용하기
 - index.js를 오픈하여 이미지 파일이나 CSS 파일, JavaScript 파일 등과 같은 정적 파일을 제공하기 위해 
   Express.js의 express.static() 메서드를 추가합니다. 정적 파일들이 들어있는 폴더로 public 폴더를 설정하였습니다.
 - 폴더에 public 폴더를 생성합니다.
 - public 폴더에 index.html 파일을 생성합니다.
 - npm start를 실행합니다.
  

   D:\_nodejs\nodePjt>npm run start



 - 브라우저에서 "http://localhost:8080/index.html"를 입력


반응형
반응형

Node.js | split() function

function splitStr(str) {
     
    // Function to split string
    var string = str.split("*");
     
    console.log(string);
}
 
// Initialize string
var str = "Welcome*to*GeeksforGeeks";
 
// Function call
splitStr(str);
반응형
반응형

First, you set the public (folder) as static in the server.js

server.js

// configure our application
const Express = require('express');
const app = new Express();
.......
.......
app.use(Express.static(__dirname+'/public'));
.......

then your html file

<img class="logo" src="/images/Heading.png" alt="My_Logo">

your images path location-

project(root folder) \ public \ images\ Heading.png

반응형
반응형

nodeJS의 무중단 관리도구인 Forever 에 대해 알아보겠습니다

node . js 앱을 실행시키거나 비정상 종료되었을 때 재실행을 시켜주는 관리도구입니다

1.forever 설치

npm install forever -g
 

2.forever 시작

forever start [js script]
 

3.forever 종료

forever stop [js script]
 

4.forever 목록

forever list

반응형
반응형

'Node.js 모범 사례'

 

       1. 프로젝트 구조 설계

       2. 에러 처리 방법

       3. 코드 스타일

       4. 테스트 및 전체 품질 관리

       5. 운영 환경으로 전환하기

       6. 보안

       7. 성능

 

https://github.com/goldbergyoni/nodebestpractices/blob/master/README.korean.md

 

goldbergyoni/nodebestpractices

:white_check_mark: The Node.js best practices list (May 2020) - goldbergyoni/nodebestpractices

github.com

 

반응형
반응형

[NodeJS] Realtime Chat with Node.js


http://tutorialzine.com/2014/03/nodejs-private-webchat/


In this tutorial, we are going to build a realtime chat system with Node.js and the socket.io library. The chat permits users to create private chat rooms that they can share with a friend. For avatars, we will use gravatar. You can run the chat locally with node, or push it to heroku or a different cloud service provider.

The code

You can grab the source code from the download button above. It has plenty of comments and is easy to follow. Start with the app.js file and read from there. Here are a few things to look for:

  • All dependencies are declared in the package.json file. They are not included in the zip and you will have to run npm install to get them.
  • We are using separate JavaScript files for the configuration and routes, to make the code more manageable.
  • In the routes file, socket.io stores the username, avatar and room of the person as properties of the socket object itself. This saves us a lot of code and makes managing rooms easy.
  • We use socket.io‘s rooms feature to isolate one chat from another, which is exactly what that feature was developed for.
Enter your name to chat

Enter your name to chat


반응형
반응형

A-Frame: A framework for the virtual reality web

 

A-Frame

For the core library, check out A-Frame Core.

Building blocks for the VR Web.

  • Virtual Reality: Drop in the library and have a WebVR scene within a few lines of markup.
  • Based on the DOM: Manipulate with JavaScript, use with your favorite libraries and frameworks.
  • Entity-Component System: Use the entity-component system for better composability and flexibility.

Find out more:

 

 

A-Frame is a framework for building things for the virtual reality web. You can use markup to create VR experiences that work across desktop, iPhones, and the Oculus Rift.

a-frame

 

 

 

 

 

.

반응형
반응형

CodeceptJS: Acceptance testing for NodeJS

CodeceptJS offers modern era acceptance testing for NodeJS. It’s scenario driven, backend agnostic, and uses an interactive shell.

codeceptjs


반응형

+ Recent posts