使用场景:
1. 在NodeJs文件中, 经常用到require 和 import 包含其他文件进来:
例如:
const User = require('db');
const User = require('./db.js');
const User = require('../db.js');
const User = require('../../db.js');
import register from './register'
简单来说:
./ 是指的当前路径;
../是指的父节点路径
如果在node_modules库中的文件,不需要指明路径. 其他的情况都需要指定.
2. 如果在控制台下来写
例如:
C:Program Files
odejs
ubdiv> node server.js ---- 当前路径下
C:Program Files
odejs
ubdiv>node ./src/server.js --- src路径下
3. 如果在Packet.ASON文件中,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"start": "node .\src\main.js",
"server": "nodemon .\src\server.js --ignore client"
},
需要用双斜杠.