gpt4 book ai didi

javascript - 在终端运行js文件

转载 作者:行者123 更新时间:2023-11-30 15:28:24 28 4
gpt4 key购买 nike

我试图在一个空文件夹中运行这个简单的文件

// time.js
const moment = require('moment')

function getDay() {
var today = moment().day()
console.log(today);
}

getDay()

使用 node time.js

但是我明白了

Error: Cannot find module 'moment'

但是我已经运行了 npm install -g momentnpm install moment

我在做什么菜鸟错误?

最佳答案

只需在文件夹内的控制台上执行以下命令:

npm init // just hit enter some times or follow the process
npm install moment --save
node time.js

注意:您可以跳过 npm init 部分,但由于依赖控制,我不推荐它。

关于javascript - 在终端运行js文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42615401/

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