【NodeJS】-init

创建NodeJS项目。

#新建一个空文件夹

mkdir ReactGame

#生成pakeage.json文件(这个文件主要是用来记录这个项目的详细信息的,它会将我们在项目开发中所要用到的包,以及项目的详细信息等记录在这个项目中。方便在以后的版本迭代和项目移植的时候会更加的方便。也是防止在后期的项目维护中误删除了一个包导致的项目不能够正常运行。使用npm init初始化项目还有一个好处就是在进行项目传递的时候不需要将项目依赖包一起发送给对方,对方在接受到你的项目之后再执行npm install就可以将项目依赖全部下载到项目里。)

npm init

package name: (reactgame)
version: (1.0.0)
description: 2048
entry point: (index.js) // module ID,项目入口。如果有人安装了你的项目,并通过require('reactgame'),那么将返回文件中的exports对象
test command:
git repository: // 代码存放在GitHub的地址

keywords: myKeywords
author: Abby
license: (ISC)

--生成的package.json

{
  "name": "reactgame",
  "version": "1.0.0",
  "description": "2048",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "myKeywords"
  ],
  "author": "Abby",
  "license": "ISC"
}

 #按照package.json中的main配置路径,创建入口文件index.js

(1)安装request

npm i request -S
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142

 request自2020-02-11被弃用,所以我要使用node-fetch代替。

npm i node-fetch -S

(2)index.js

const fetch = require('node-fetch');

(async () => {
  const response = await fetch('https://api.github.com/users/github');
  const json = await response.json();

  console.log(json);
})();

 

posted on 2020-09-02 21:00  WhoLovesAbby  阅读(541)  评论(0)    收藏  举报