Joseph Le Brech
Joseph Le Brech

Reputation: 6653

How do you include npm libraries in a node.js app

I'm trying to create a little app with node-ncurses which I installed over npm install ncurses

with this library install i'm trying to run the examples for node-ncurses from the following

https://github.com/mscdex/node-ncurses/tree/master/examples

But I get path errors with the examples for require('ncurses'), what is wrong?

My ncurses library is install into ~/.npm/ which seems correct to me.

Upvotes: 0

Views: 476

Answers (2)

Jack Franklin
Jack Franklin

Reputation: 3765

You want to be installing them locally into the same folder of your project. If you miss out the -g flag and just run npm install ncurses within your project directory, you should then be able to run require("ncurses") just fine. All NPM modules installed locally goes into a node_modules folder within your project.

A little further hint, if you install with:

npm install ncurses --save

That will add ncurses to your package.json as a dependency, which means any other dev who might check out your project can run npm install in the project's directory and automatically get ncurses installed as it's listed in package.json as a dependency.

Upvotes: 3

Dan
Dan

Reputation: 1721

Without the -g flag anything you install with NPM with install into a node_modules folder relative to where you ran the command.

My first recommendation would be to make sure that you are in the working directory of your project and then install ncurses again.

Here is an old, but relevant blog post about how it was designed.

Upvotes: 1

Related Questions