(之前已安装好node.js与thinkjs)
1.安装前复查node.js及thinjs的版本
检查node.js版本:
node -v
检查thinkjs版本:
thinkjs -V
2.创建thinkjs项目
C:\Users\宛\Desktop>cd stu/
C:\Users\宛\Desktop\stu>thinkjs new demo
执行过程中会要求我们输入项目名称、项目简介、作者、是否开启 babel 转译,结果如下:
? Project name study
? Project description application created by thinkjs
? Author wan
? Do you want to turn on babel? No
由于我的node.js的版本号大于8.0,因此我选择了不转译
之后安装依赖:(项目下的package.json就是它的依赖)
npm install
这里出现了一堆警告,但我没有当回事儿:
npm WARN saveError ENOENT: no such file or directory, open 'C:\Users\宛\Desktop\stu\package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\宛\Desktop\stu\package.json'
npm WARN stu No description
npm WARN stu No repository field.
npm WARN stu No README data
npm WARN stu No license field.
启动项目:
npm start
但是这里报错了:
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:\Users\宛\Desktop\stu\package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\宛\Desktop\stu\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\宛\AppData\Roaming\npm-cache\_logs\2020-05-20T03_43_18_668Z-debug.log
解决问题做出的尝试:
(1)删除用户目录下的npmrc文件,发现不行(必须开启隐藏的项目才会看到)
(2)之后我想到会不会与install时发出的警告有关,于是搜索解决警告的方式:
(这里参考的笔记为:这里是超链接https://blog.csdn.net/weixin_40161974/article/details/99441501)
按照博主的方法尝试输入
npm init
执行过程中的询问:
description:
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to C:\Users\宛\Desktop\stu\package.json:
save it as a dependency in the package.json file.
{
"name": "study",me to quit.
"version": "1.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Is this OK? (yes)
之后我重新进行npm install与npm start,在npm start时又遇到报错(要疯):
npm ERR! missing script: start
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\宛\AppData\Roaming\npm-cache\_logs\2020-05-20T03_55_56_060Z-debug.log
又查找相关资料,参照此篇笔记:
这里是超链接https://www.h5w3.com/856.html
我cd到项目目录中,即:
C:\Users\宛\Desktop\stu>cd demo
之后再进行npm install 与npm start之后:
> study@1.0.0 start C:\Users\宛\Desktop\stu\demo
> node development.js
[2020-05-20T12:01:48.568] [75240] [INFO] - Server running at http://127.0.0.1:8360
[2020-05-20T12:01:48.575] [75240] [INFO] - ThinkJS version: 3.2.11
[2020-05-20T12:01:48.576] [75240] [INFO] - Environment: development
[2020-05-20T12:01:48.577] [75240] [INFO] - Workers: 1
logic deprecated logic's __after method is deprecated, it will be discarded in the next version node_modules\koa-compose\index.js:42:32
[2020-05-20T12:03:55.255] [80940] [INFO] - GET / 200 20ms
[2020-05-20T12:03:55.395] [80940] [INFO] - GET /favicon.ico 404 10ms
参照提供的网址,进入http://127.0.0.1:8360:
创建成功