简体   繁体   English

收到节点模块文件夹后,安装npm软件包

[英]Installing npm packages, after recieving the node modules folder

My name is Jaffer Syed and I am wondering how to install npm packages into my code. 我的名字叫Jaffer Syed,我想知道如何将npm软件包安装到我的代码中。 I am trying to install num2fraction https://www.npmjs.com/package/num2fraction but in you npm package video you didnt go into how to install npm packages and how to actually make it work in the javascript. 我正在尝试安装num2fraction https://www.npmjs.com/package/num2fraction,但是在您的npm软件包视频中,您并没有研究如何安装npm软件包以及如何使其真正在javascript中工作。 I added the command for the package in the command line but it doesn't seem to work for some reason and when I find the error it keeps saying that the require is not defined. 我在命令行中为软件包添加了命令,但是由于某种原因它似乎不起作用,当我发现错误时,它总是说未定义require。

my js looks like this for trying to implement the num2fraction 我的js看起来像这样尝试实现num2fraction

    var n2f = require('num2fraction')

     console.log(n2f(2.555)) 

thank you 谢谢

here is a sample script for how I did what you're trying: 这是我如何做的示例脚本:

mkdir foo
cd foo
npm init

just accept all the default options here 只接受这里的所有默认选项

npm install -s num2fraction

put your exact contents above into a file called foo.js in this directory and save 将上面的确切内容放入此目录中的名为foo.js的文件中并保存

node foo.js

should output 511/200 应该输出511/200

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM