I'm new to node.js, I would like to use Step.js
https://github.com/creationix/step
The install instructions are very simple:
"Simply copy or link the lib/step.js file into your $HOME/.node_libraries folder."
The problem is that I can't find the .node_libraries folder anywhere.
I tried to create the folder myself and upload the step.js file but I get the following error:
ReferenceError: Step is not defined
I tried to create the following directories:
home/service/.node_libraries
root/.node_libraries
/usr/local/bin/.node_libraries
but none of them works.
Also, Is it possible to load Step as a module?
Thankyou
They have an npm module.
Simply run npm install --save step in the same dir your package.json resides and then you can require() it in your code like this:
var Step = require('step');
The documentation is outdated.
you should use the node package manager.
open the command line in the folder and write:
npm install step
also remember to include the module in your javascript file:
var Step = require('step');
Related
I'm trying to create a node module that has the ability to be installed globally using npm install -g mymodulename. I've got everything in the module working fine if I run node index.js in the directory of the module, but now I want to make it so that I can publish it to NPM, and it can be installed and run from any directory.
There is some code in my module that looks at certain files in the directory that it is run in. I'm finding that when I do npm install -g ./ and then go into a different directory for a test, then run my-module-command, the relative path that it is reading is from that of where my module got installed (i.e. /usr/local/bin/my-module), not the directory that I'm running it in.
How can my module that is installed globally know where it is being run from? To give an example, I am trying to read the package.json file in the directory I'm in. And it is reading the package.json file of /usr/local/bin/my-module/package.json
I've tried:
__dirname
process.args[1]
process.cwd()
And just calling straight to require('./package.json') directly and none of those work.
Edit here's some code that's breaking in index.js:
#!/usr/bin/env node
var fs = require('fs');
var path = require('path');
var currentDir = path.dirname(require.main.filename);
fs.exists(`${currentDir}/node_modules`, function(dir) {
if (!dir) throw 'node_modules does not exist';
// do stuff
});
In my package.json:
...
"bin": {
"my-module": "./index.js"
},
...
I try to do npm install -g ./ in the project directory, and then I cd into a different directory called /Users/me/Projects/different-project, where another npm project is, and run my-module, and I get node_modules does not exist. When I log out currentDir, I get /usr/local/lib/node_modules/my-module where I'm expecting is to see /Users/me/Projects/different-project.
Have you tried using ./ at the start of your file path? That should give you the current working directory (or calling process.cwd() would work too).
In your case, your code would look like:
fs.exists(`./node_modules`, function(dir) {
if (!dir) throw 'node_modules does not exist';
// do stuff
});
I can see some comments already mention this. Maybe I'm misunderstanding the question? I just had a case where I needed a global module to get the directory I'm running the script from and what I suggested above worked like a charm.
I recently started on ember JS.
I am trying to import bootstrap.css file from "node_modules\bootstrap\dist\css\bootstrap.css"
But when i run the server its shows error like
Error: ENOENT: no such file or directory, open 'E:\For Saving\ember\project2\new_project\tmp\simple_concat-input_base_path-JBlVqJm6.tmp\node_modules\bootstrap\dist\css\bootstrap.css'
It is adding some path with my path and giving me this error. I search a lot to solve this but i can't. And Also i installed the bower via npm and the bower_component is not getting added into my project folder.
Last thing I am not good with command Line Interface. can i run ember without terminal?
You can't app.import node modules files. It's only for bower components and vendor folder.
Reference from ember-cli documentation.
I have a command line tool written in node. I'd like to:
Have the app be able to load its dependencies and work. Currently, after npm install -g <somemodule> that module is still not available. Things didn't used to work this way.
Not have to run npm link on every folder, as I have read in the NPM 1.0 docs. The above docs also talks about $PATH, which seems unrelated to the topic as I care about node modules, not binaries.
How can/should a node command line tool handle its dependencies so that the command line tool can run from any directory?
You can add following in the main file of your node.js app, assuming your file name is node-binary.js.
#! /usr/bin/env node
// your app code
console.log('TEST node binary');
And, in package.json file you need to specify which is the entry point of your app
...
"preferGlobal": "true",
"bin": {
"node-binary": "node-binary.js"
},
...
and run the command npm link in the app directory. You should now be able to use node-binary command from any directory.
Hope that helps... :)
I can't run the command express from the windows 7 command line. A tutorial I am following (here) suggests that I use the command line and call express to build a skeleton application.
I move into the directory of the express module in my node_modules area and attempt to locate a batch file or executable that is able to run from the command line.
I have found nothing, there are no files included in the module that can be run from the command line.
I am now very confused.
Does anyone understand where this elusive express command line utility exists?
I have found the batch file.
All command files for modules that are meant to be invoked via the command prompt are found in node_modules\.bin
So make sure that is in your path environment variable.
It looks like Jonathan Lonowski was right - the guide is a bit outdated. The latest command for using the express generator is:
npm install -g express-generator
This will still give the same directory structure suggested in the tutorial.
More info on Express's Github page
You need to install the Express application generator, as described in Express Getting started document. Install it with the following command:
$ npm install express-generator –g
After that, you can run the command express from any windows 7 command line.
I want to ask how can I add modul to node.js. I me I've installed node.js and want to create a simple form for uploading image. When I require a 'formidable' module and create a new object from it, i get an error 'cannot find the modul formidabe' .
Via npm (the node package manager), try this from your command line:
npm install formidable
as explained in the docs. After that it should work.