Obtain resources from the NPM repository

I recently encountered an issue while trying to utilize font-awesome with npm. The newest version (>4) made it challenging to locate the fonts directory.

Previously, I used a npm script similar to

cp -R ./node_modules/font-awesome/fonts/* dist/assets/
. However, this method no longer works when my library is incorporated into a program that organizes all modules in the root directory.

Is there a reliable way to determine the location of the fonts or any other technique to achieve the same outcome?

Thank you

Answer №1

I have found a helpful solution: I created an npm tool to display the path of node_modules directory https://github.com/lexoyo/node_modules-path

This utility can be set up as a ".bin" script for easy access in npm scripts, and it outputs Path.resolve(__dirname, '..');.

You can incorporate this into your package.json or shell scripts like so:

$ mkdir -p dist/fonts
$ cp -R `node_modules`/font-awesome/fonts/* dist/fonts/"

The tool defines the NODE_MODULES environment variable which allows you to utilize it as shown below, although I have not personally tested this feature:

$ mkdir -p dist/fonts
$ node_modules
$ cp -R ${NODE_MODULES}/font-awesome/fonts/* dist/fonts/"

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Restoring NPM packages within Visual Studio is always done in the System32 directory

Every time I attempt to execute the Restore Packages command by right-clicking on the package.json file, the output below is displayed: PATH=.\node_modules\.bin;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External ...

I encountered difficulty executing a nodejs child_process on my Amazon EC2 instance

I'm utilizing the nodejs child_process function spawn() to execute a mongoexport. I have provided all the necessary parameters to the command and it's functioning correctly on my local setup. Below is the code snippet for the function: userDetai ...

Exploring the functionality of the readline module using a simulated command-line

I am currently working on developing a unit test for a module that utilizes the "readline" functionality to interpret standard input and provide standard output. Module: #!/usr/bin/env node const args = process.argv.slice(2) var readline = require(' ...

The error message "NodeJS TypeError: Model is not a constructor" indicates that

I am facing an issue with my Angular5 app making requests to my NodeJS Api. Specifically, when I try to make a put request, it works the first time but throws an error on the second attempt saying that my Model is not a constructor. In my NodeJS backend, I ...

Setting up KeystoneJS Application with Let's Encrypt and Heroku

I am utilizing the letsencrypt feature of KeystoneJS to conveniently set up and manage HTTPS details for my project. I would like to configure this to function with a custom domain on Heroku. I have followed a previous guide to successfully configure the H ...

Error: The property 'send' cannot be read because it is undefined - Node.js

We have integrated a Node.js package called springedge to handle SMS functionality in our project: npm install springedge Below is the code snippet from the file send_messages.js: var springedge = require('springedge'); var params = { &apos ...

To effectively run the Angular Compiler, it is necessary to have TypeScript version greater than or equal to 2.7.2 but less than 2.8.0. However, the system detected

I am encountering an error in my Angular application that reads: The Angular Compiler is asking for TypeScript version >=2.7.2 and <2.8.0, but it found 2.8.3 instead. When I attempt to downgrade TypeScript to the correct version by running: npm instal ...

Tips for structuring route dependencies in Node.js and Express

Although I have a good grasp of exporting routes to an index.js file, my struggle lies in properly referencing external route dependencies without having to copy them to the top of the file. For instance, if I have the main entry point of the program (ind ...

Tips for optimizing MongoDB query performance with larger datasets

When querying a MongoDB collection for data matching more than 10000 entries, even with an index in place, the query time exceeds 25 seconds. For instance, let's consider a table called People with fields name and age. I am trying to retrieve People ...

Why is ExpressJS req.user giving back undefined?

Why is the user returning undefined? I am completely lost export const getCurrentUser = async (req, res) => { // fetch user console.log(req.user) const user = await User.findOne({ _id: req.user.userId }) // fetch withdraws res.send({ curre ...

An issue occurred while trying to execute the `ionic serve` command, and the result of

Facing an issue with the ionic serve command - I keep getting the error message "Hmm, we can't reach this page" and when attempting to view the result of the ionic address command, there is no output. Any assistance in resolving this would be greatly ...

Error encountered when trying to connect Solidity contract with React Next.js, issue with fetching contract through NPM package

My goal is to create an NFT marketplace, but I've encountered a problem with npm run dev. It was working fine yesterday, but now it's not letting me fetch functions from NFTMarketPlace.sol after exiting VSCode. I tried deleting node_modules & ...

Is there a way to divide my time during work hours using Javascript?

This is just a simple example. 9.00 - 18.00 I am looking to modify the schedule as follows: 9.00 - 10.00 10.00 - 11.00 11.00 - 12.00 12.00 - 13.00 13.00 - 14.00 14.00 - 15.00 15.00 - 16.00 16.00 - 17.00 17.00 - 18.00 The current code implementation see ...

When restarting nginx, Angular fails to display the index page

On my VPS server, I have an application with the backend coded in node.js and the frontend in Angular. After restarting nginx, I encountered some issues where my API stopped working on HTTPS and only functioned on HTTP (previously, I was able to make requ ...

create a routemap or manage a handler

i currently have a controller set up exports.updateDaily = async (req, res) => { try { const updateDaily = await transaction.decrement( { remainActive: 1, }, { where: { remainActive: { [Op.gte]: 1 }, ...

Are there any alternatives in NodeJS similar to PyAutoGUI that have the ability to search for an image within a screenshot?

I've been working on developing a bot to automate tasks in a video game using JS and Node, primarily utilizing RobotJS. However, I'm encountering an issue where I need to locate and click on a moving element on the screen, similar to PyAutoGUI&ap ...

I need to verify whether the data has been saved already, and if not, I would like to save it to my MongoDB database

I have the following code in use, where I need to avoid saving a document with the same UUID: const mongoose = require('mongoose'); mongoose.connect("mongodb+srv://connection string", {useNewUrlParser: true}); var db = mongoose.connection; con ...

The error message "npm start error - No production canister_ids.json can be located. Proceeding with local

Every time I execute npm start, the same "error" message pops up saying "No production canister_ids.json found. Continuing with local" Initially, there appeared to be a proxy issue that was visible in the browser console. I was able to resolve it by makin ...

Encountering an issue with a Next.js app where it has become stuck during execution, the command "npm run dev

After successfully creating a simple next.js app and starting it with npm run dev, I encountered an issue when trying to start it for the second time: enter image description here Even after attempting to create a new project, the problem persisted. Inte ...

Deleting a MongoDB entry with Node.js and Handlebars is not possible

I have been struggling to figure out how to delete an entry but haven't had any success yet. I've tried using "post" instead of "delete" without any luck and even attempted the action request on the html, but still no success. I'm really stu ...