NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

How to use a npm module

 
Post new topic   Reply to topic    NetBeans Forums -> Web Client Users
View previous topic :: View next topic  
Author Message
owengerig



Joined: 26 Apr 2016
Posts: 1

PostPosted: Tue Apr 26, 2016 5:20 pm    Post subject: How to use a npm module Reply with quote

Im am fairly new to some of this so please bare with me.

I am trying to use a node module called sftp-ws. Via my project's properties I have added it as an npm package which in turn automatically added it to the <project>\npm libraries, location.

According to the samples for the sftp-ws I should declare my object as
Code:
var SFTP = require("sftp-ws");


However that alone gives me the error
Uncaught ReferenceError: require is not defined

So after researching that I installed another npm package browserify in hopes of getting the require method working. However similiar to the sftp package this module gets add to the npm libraries and from there im not sure how to use it.

What am I missing, how do I use these npm packages or the require method?
Back to top
vriha



Joined: 07 Feb 2013
Posts: 135

PostPosted: Thu Apr 28, 2016 5:37 am    Post subject: How to use a npm module Reply with quote

Hi,
this looks like you are trying to run NodeJS code in browser? NodeJS is
loading modules using the require() call, this function does not exist
in browser (there is RequireJS framework for loading modules, but only
RequireJS modules, not NodeJS).

So if you want to use the sftp-ws NPM module, you need to run the
JavaScript file on NodeJS, not in browser. You can check e.g. this video
https://www.youtube.com/watch?v=b3giUSvRjPc about how to create/run
NodeJS project in NetBeans or check
http://wiki.netbeans.org/NewAndNoteworthyNB81#Node.js_Support


Lada


On 26/04/16 19:20, owengerig wrote:
Quote:
Im am fairly new to some of this so please bare with me.

I am trying to use a node module called sftp-ws. Via my project's properties I have added it as an npm package which in turn automatically added it to the <project>\npm libraries, location.

According to the samples for the sftp-ws I should declare my object as

Code:
var SFTP = require("sftp-ws");



However that alone gives me the error
Uncaught ReferenceError: require is not defined

So after researching that I installed another npm package browserify in hopes of getting the require method working. However similiar to the sftp package this module gets add to the npm libraries and from there im not sure how to use it.

What am I missing, how do I use these npm packages or the require method?



Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Web Client Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo