gpt4 book ai didi

javascript - 多个 var 是 node app.js

转载 作者:行者123 更新时间:2023-11-30 09:52:52 25 4
gpt4 key购买 nike

调用多个 var 是否是错误的形式,例如:

 var init = require('./config/init')(),
config = require('./config/config'),
express = require('express'),
errorHandler = require('errorhandler'),
bodyParser = require('body-parser'),
expressValidator = require('express-validator'),
mongoose = require('mongoose'),
path = require('path'),
_ = require('lodash'),
passport = require('passport'),
passport_config = require('./config/passport'),
session = require('express-session'),
MongoStore = require('connect-mongo')(session),
swagger = require("swagger-node-express"),
secrets = require('./config/secrets'),
multer = require('multer');

还是我应该自己设置每一个?

最佳答案

因为您使用它在全局范围内导入 npm 模块,所以没问题。但一般来说,更好的做法是为每个变量声明 var。原因是缺少 , 将在全局范围内创建任何后续变量。例如, try catch 以下错误:

var init = require('./config/init')(),
config = require('./config/config'),
express = require('express'),
errorHandler = require('errorhandler'),
bodyParser = require('body-parser')
expressValidator = require('express-validator'),
mongoose = require('mongoose'),
path = require('path'),
_ = require('lodash'),
passport = require('passport'),
passport_config = require('./config/passport'),
session = require('express-session'),
MongoStore = require('connect-mongo')(session),
swagger = require("swagger-node-express"),
secrets = require('./config/secrets'),
multer = require('multer');

关于javascript - 多个 var 是 node app.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35472209/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com