簡體   English   中英

如何使用express,ejs將function從a.js模塊導入node js中的another.js模塊

[英]how to import function from a .js module to another .js module in node js, using express, ejs

您好我正在嘗試將 function 從 js 文件導入另一個 js 文件,這些文件是節點 js 中的客戶端,因此我不能使用 require 方法。 I cannot use the import statement unless I add type: module in package.json file and if i do, I have to find a way to import ejs as I cannot use require method adding type: module in package.json. 有什么建議嗎??

請在下面找到 app.js 的代碼:

APP.JS

const express = require("express");
const app = express();

const ejs = require("ejs");

app.use("/public", express.static(__dirname + "/public"));
app.use("/public", express.static(__dirname + "/"));

歡迎堆疊。 問題不清楚。 我可以添加一些可能對您有所幫助的示例。

 const getAlgoValue = (averageValue) => { let number = 3.5 / Math.pow(averageValue, 0.7) + 1.5; return number; }; exports.getAlgoValue = getAlgoValue;

這是我export的 function,我需要將其導入另一個文件才能使用它。

 const { getAlgoValue } = require('./getAlgo');

希望我對你有所幫助。 一些可以幫助module.exports的資源

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM