我有一个Node + Express应用程序。在我的许多文件中,我在顶部
这样做const config = require('./config');
const Twit = require('twit');
const TwitConnector = new Twit(config);
有没有办法干这个,所以我不必在任何地方重复这个?
是否有一种最佳实践模式可以使TwitConnector
全局可用,以便我可以随时使用它?
或许这不是一个好主意,明确要求它是正确的做法?
答案 0 :(得分:2)
你不能制作twit-connector.js文件而需要这样做吗?我不认为让它全球化是一个好主意。
<强>蠢-connector.js 强>
@charset "utf-8";
.Wrapper {
width: 100%;
height: auto !important;
height: 100%;
min-height: 100%;
margin-bottom: 200px;
padding: 0;
margin: 0;
}
.Push {
height: 1000px;
}
.MainFoot,.BiologyFoot {
height: 200px;
}
.parallax {
height: 100%;
background-attachment: fixed;
background-position: top;
background-repeat: no-repeat;
background-size: cover;
}
.first {
background-image: url(../Images/Fon2.jpg);
}
html {
height: 100%;
padding: 0;
margin: 0;
}
body
{
height: 100%;
margin: 0;
padding: 0;
/* make it look decent enough */
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
color: #cdcdcd;
font-family: "Avenir Next", "Avenir", sans-serif;
overflow-x: hidden; /* needed because hiding the menu on the right side is not perfect, */
}
body.Main {
background-image: url(../Images/FonMain2.jpg);
}
body.Biology {
background-image: url(../Images/FonMain4.jpg);
}
header {
padding: 0;
margin: 0;
max-width: 100%;
height: 100px;
background: linear-gradient(rgba(0,0,0,0.8), rgba(0,0,0,0.8), rgba(0,0,0,0.0));
}
.BiologyHead {
background: linear-gradient(rgba(40,40,40,1.00), rgba(20,20,20,1.00));
position: fixed; left: 50px; right: 50px; top: 0;
z-index: 1;
}
.MainFoot {
width: 100%;
height: 250px;
background: linear-gradient(rgba(0, 0, 0, 0.00),rgba(9, 35, 3, 1.00));
}
.BiologyFoot {
border-style: none;
position: fixed; left: 50px; right: 50px; bottom: 0;
background: linear-gradient(to top,rgba(40,40,40,1.00), rgba(20,20,20,1.00));
z-index: -1;
}
h1 {
display: block;
max-width: 15%;
}
.Text1{
display: block;
color: rgba(57,55,236,1.00);
max-width: 10%;
position: absolute; top: 1px; right: 10px;
padding-right: 85px;
}
.Content {
background: rgba(39,39,39,1.00);
height: 100%;
max-width: 100%;
position: absolute; left: 50px; top: 100; right: 50px;
background-size: cover;
margin-top: 100px;
margin-bottom: 0;
}
.Content1 {
position: absolute; left: 70px; right: 70px; top: 0;
background: linear-gradient(to right, rgba(255,255,255,0.0), rgba(255,255,255,0.50), rgba(255,255,255,0.50), rgba(255,255,255,0.50), rgba(255,255,255,0.00));
background-size: cover;
max-width: 100%;
height: 100%;
margin-left: 70px;
margin-right: 70px;
padding-top: 20px;
font-family: Cambria, "Hoefler Text", "Liberation Serif", Times, "Times New Roman", "serif";
}
img.EducationInside {
margin-top: 10px;
margin-bottom: 10px;
margin-left: 10px;
margin-right: 10px;
max-width: 95%;
}
p {
margin-left: 10px;
margin-right: 10px;
}
img.EducationFace {
float:right;
margin: 10px;
max-width: 30%;
padding-left: 10px;
}
img.EducationLegs {
float:left;
margin: 10px;
max-width: 30%;
padding-left: 10px;
}
img.EducationEyes {
float:right;
margin: 10px;
max-width: 20%;
padding-left: 10px;
}
img.Decoration {
max-width: 50%;
position:absolute;
bottom: 100%;
opacity:0;
animation:load_up 2s forwards;
-webkit-animation:load_up 2s forwards;
}
@keyframes load_up{
from{opacity:0;bottom:100%}
to{opacity:1;bottom:20%;}
}
@-webkit-keyframes load_up{
from{opacity:0;bottom:100%}
to{opacity:1;bottom:20%;}
}
a
{
text-decoration: none;
color: rgba(156,233,210,1.00);
transition: color 0.3s ease;
}
a:hover
{
color: rgba(96,229,132,1.00);
}
#menuToggle
{
display: block;
position: absolute;
top: 15px;
right: 15px;
z-index: 1;
-webkit-user-select: none;
user-select: none;
}
#menuToggle input
{
display: block;
width: 40px;
height: 32px;
position: absolute;
top: -7px;
left: -5px;
cursor: pointer;
opacity: 0; /* hide this */
z-index: 2; /* and place it over the hamburger */
-webkit-touch-callout: none;
}
/*
* Just a quick hamburger
*/
#menuToggle span.Bio
{
display: block;
width: 33px;
height: 4px;
margin-bottom: 5px;
position: relative;
background: rgba(54,71,124,1.00);
border-radius: 3px;
z-index: 1;
transform-origin: 4px 0px;
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
background 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
opacity 0.55s ease;
}
#menuToggle span.Home
{
display: block;
width: 33px;
height: 4px;
margin-bottom: 5px;
position: relative;
background: rgba(154,112,80,1.00);
border-radius: 3px;
z-index: 1;
transform-origin: 4px 0px;
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
background 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
opacity 0.55s ease;
}
#menuToggle span:first-child
{
transform-origin: 0% 0%;
}
#menuToggle span:nth-last-child(2)
{
transform-origin: 0% 100%;
}
/*
* Transform all the slices of hamburger
* into a crossmark.
*/
#menuToggle input:checked ~ span
{
opacity: 1;
transform: rotate(45deg) translate(-2px, -1px);
background: #232323;
}
/*
* But let's hide the middle one.
*/
#menuToggle input:checked ~ span:nth-last-child(3)
{
opacity: 0;
transform: rotate(0deg) scale(0.2, 0.2);
}
/*
* Ohyeah and the last one should go the other direction
*/
#menuToggle input:checked ~ span:nth-last-child(2)
{
opacity: 1;
transform: rotate(-45deg) translate(0, -1px);
}
/*
* Make this absolute positioned
* at the top left of the screen
*/
#menu
{
position: absolute;
width: 180px;
height: 100px;
margin: 10px 0 0 0;
padding: 50px;
padding-top: -150px;
right: -100px;
overflow-y: scroll;
background: linear-gradient(rgba(0,0,0,0.00), rgba(0,0,0,0.55), rgba(0,0,0,0.00));
list-style-type: none;
-webkit-font-smoothing: antialiased;
/* to stop flickering of text in safari */
transform-origin: 0% 0%;
transform: translate(100%, 0);
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0);
}
#menu li
{
padding: 10px 0;
font-size: 22px;
}
/*
* And let's fade it in from the left
*/
#menuToggle input:checked ~ ul
{
transform: scale(1.0, 1.0);
opacity: 1;
}
canvas{
display:block;
padding: 0;
margin: 0;
vertical-align: bottom;
}
/* ---- particles.js container ---- */
#particles-js{
max-width: 100%;
height: 200%;
padding: 0;
background-color: rgba(20,20,20,1.00);
background-size: cover;
background-position: 100% 100%;
background-repeat: no-repeat;
margin-bottom: 200px;
}
/* Login */
.Email {
width: 90px;
height: 15px;
border-radius: 4px;
border-style: none;
position: absolute; top: 17.5px; right: 285px;
font-size: 11px;
}
.mail {
position: absolute; top: 19px; right: 379px;
font-size: 13px;
color: #fff;
}
.Password {
width: 90px;
height: 15px;
border-radius: 4px;
border-style: none;
position: absolute; top: 17.5px; right: 120px;
font-size: 11px;
}
.pass {
position: absolute; top: 19px; right: 215px;
font-size: 13px;
color: #fff;
}
.Submit {
width: 50px;
height: 17px;
position: absolute; top: 17.5px; right: 60px;
background: rgba(54,71,124,1.00);
border-radius: 4px;
border-style: none;
font-size: 10px;
color: #fff;
}
@media only screen and (max-width: 1000px) {
body {
margin: 0px;
padding: 0px;
}
section {
font-size: 70%;
}
}
@media only screen and (max-width: 700px) {
body {
margin: 0px;
padding: 0px;
}
section {
font-size: 50%;
}
}
<强> somefile.js 强>
const config = require('./config');
const Twit = require('twit');
const TwitConnector = new Twit(config);
module.exports = TwitConnector;