I'm trying to use gtfs-realtime-bindings' node module.
The published module on npm is outdated so I'm downloading directly from github. However, gtfs-realtime-bindings is a super repo has subfolders for a lot of different environments.
How can I specify a subfolder in my require?
After downloading and extracting the zip file, you can npm install the relative path to your dependencies by running it in the root of your project like this:
npm i ../gtfs-realtime-bindings/nodejs --save
This is assuming that you've extracted the git repository zip adjacent to the project root directory. In your code you can then require('gtfs-realtime-bindings') like you would any other dependency installed via npm.
Are you downloading the repo and inserted on your source code? You should be able to use import or require from anywhere, example.
code
__src
____index.js
__gtfs-realtime-bindings
____nodejs
____java
You should be able to get the nodejs files from the index.js using
import nodejs from "../gtfs-realtime-bindings/nodejs";
or
const nodejs = require("../gtfs-realtime-bindings/nodejs");
Obviously, this depends on what you are trying to get, I don't know that repo, but this should work
Related
I want to try and make some changes to a package published in npm? (I've suggest some changes as an issue but I think they are simple enough for me to attempt them).
https://www.npmjs.com/package/bt-presence#contributing--modifying
The author supplies some information on how to modify the package, but not really enough for someone doing it for the first time.
Where should I clone the GitHub repo to? The folder where the package is installed? I tried it in my home folder and that would not build (unmodified).
The command npm run build - where is this run from? The root folder of the package where the package.json is?
Will I need to modify the package.json?
In general what is the best way to develop something like this for npm? I've worked on packages before but they were simply Javascript.
If you want to work on the bt-presence package in isolation, you can put the cloned repository anywhere. If you want to use your modified version of bt-presence in combination with an application, my recommended approach is to register bt-presence as a dependency in the application's package.json file with the version set to a relative path to your bt-presence repository; then running npm install in the application will make a symlink from node_modules/bt-presence in the application to your bt-presence repository.
npm run build should indeed be run from the root folder that contains the package.json of bt-presence.
If you just want to change the code of bt-presence, you won't need to modify its package.json. You would only modify the package.json if you need to change any of the settings in there, e.g, if you need to add additional dependencies to your version of bt-presence.
None of the above is really specific to TypeScript. (Some JavaScript packages have build processes too if they need to transform or package the JavaScript files in some way.)
I wish to manually install npm modules for my Angular project. I am behind a proxy and instead of setting the proxy information for my npm config file, I just wish to manually download npm modules and add them to my npm-cache/node_modules folders.
I have seen this old post but haven't found anything more recent: How to install a node.js module without using npm?
One of the modules I want to install is ng2-signalr. I went to GitHub, downloaded the source for the package, and added it to my node_modules folder.
After doing this I can import the module without error:
import { SignalRConfiguration } from 'ng2-signalr';
When I add code that uses the class:
const c = new SignalRConfiguration();
I get the following error:
index.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
Am I missing a step for manually installing a node module? Should I download to my npm cache folder?
I'm aware that I have to pay mind to dependencies of these manually installed modules. Also I know that the cache folder gets overwritten when you need to reinstall and that the node_modules folder is not usually included when you check in your source due to the size, but I only wish to experiment with the library.
Any advice?
Add the directory or index file you wish to use in your Typescript config. Example in tsconfig.app.json:
"include": [
"../path/to/library"
]
Rebuild after this. This is likely due to the 3rd party not setting up the package.json correctly.
I have an Angular2 project. In it I have a DisplayModule which contains components/directives/pipes/services used to do display stuff.
What do I have to do to make this a npm module which I can them load in other projects.
So far I have:
Extracted the folder as in a separate git folder, which contains the display.module.ts file in which I import and export all the relevant things from within this folder.
Tried to find what to do with this folder so that I can import it. From my understanding the steps are as follows:
a) do something to compile it into js files
b) export those js files as a package
c) publish those js files as a private npm package
d) include this package with npm install in another project
As you have probably guessed I have no idea how to do all the points under 2.
Please help
I want to create an npm package that would be installed globally, with a binary to call. Calling that binary would set up the initial files for a new project, like your standard folders, standard license and layouts, a package.json with your common dependencies. Then you could call npm install to actually set up that project.
Like the Express application generator, or like rails new does in Ruby. The usage would be like
mkdir new_project
cd new_project
myCoolGenerator new
npm install
But I'm confused about how I'd implement this. The simple approach, which I'm doing now, is to create the standard vanilla folder, ship it with the generator package, and then just have the main binary use ncp to copy that folder into wherever the caller currently is.
My problem there is that I don't know how I can access the folder included in the globally-installed package to copy over. And additionally, npm lets you specify a files array in your package.json to specify files included with the package, but it's apparently hardwired to ignore package.json from that.
What's the recommended procedure for this sort of thing?
I would like to download node module packages (listed in a package.json file, in the present working directory) source code to a node_modules subdirectory of the present working directory, without compiling, or installing those modules. Now I have seen the related question download source from npm without npm install xxx but that question dealt with downloading the source code of individual modules specified to NPM directly (i.e., without using a package.json file). The reason why I want to do this is because I am working on developing an Atom package for the Open Build Service (OBS) of openSUSE and this seems like one of the necessary steps I need to go through in order to achieve this.
The source code is not shipped with the npm distributed code. The best you could do is read the package.json and look for the { repository: url { } } key if it exists and if it's a git repo (which most of them will be) clone it.
However be aware that the source code often requires a build step before it can be used, as in an npm prepublish step defined in the source code. In modern Javascript projects a common example of this is transpiling ES6 code to ES5 code for use in NodeJS and the browser.
I have not made an Atom package but I'm fairly certain you don't need to do any of this.