node-modules

NodeJS require all modules in one file, good practice?

萝らか妹 提交于 2019-12-06 17:40:47
I am wondering if there is any downside, from a design or security point of view, having one file that requires() all the modules that I need, and then exports them. This would save me to keep track of all modules in every single file. Example: // my_requires.js const bodyParser = require('body-parser') const parseForm = bodyParser.urlencoded({extended: false}) const DOMPurify = require('dompurify'); const {JSDOM} = require('jsdom'); const jwt = require('jsonwebtoken'); const passport = require('passport'); require('../config/passport')(passport) module.exports = { bodyParser: bodyParser,

Having project_name/node_modules as a symlink?

十年热恋 提交于 2019-12-06 16:08:38
Related: single node_modules folder for multiple projects If npm install -g everything is not recommended, and I do not want to link individual modules, can I possibly symlink <some project>/node_modules to a common directory to be shared by multiple projects? Node can handle the symlinks perfectly fine. How to achieve this is going to depend on some of your objectives. The most important being: what experience do you want to have for other developers who download your project(s) from version control? When designing this experience, it is super helpful to read about the Node module loading

Invoke javascript callback repeatedly from C++ module in node.js

我怕爱的太早我们不能终老 提交于 2019-12-06 15:36:43
So I am writing a node.js module in C++ which processes data from a camera. I want to invoke a callback function in my app.js file whenever new data is available. What I have at the moment Right now I have in my node javascript file ( app.js ) the following code. Every second it calls a function in my C++-Module and returns the number of frames that have been processed so far: setInterval(function () { var counter = MyCPPModule.NumberOfFrames(); console.log(counter); }, 1000); In my C++ file I have the following functions. 1.) I have a function to get the number of frames - the function that

.gitignore and node_modules

夙愿已清 提交于 2019-12-06 13:43:03
I am trying to figure out the best way to handle node_modules in git. From what I read, there are two options: A. Keep all the node_modules in the git repository, together with my project. This way, a person cloning my project does not have to install any modules. B. Don't keep any node_modules in the git repository, i.e., have a ".gitignore" file that contains "node_modules". However, in some projects, I don't see any of these two options. For example, in this node.js project , there are no node_modules, but also no .gitignore file... When I fork this repo, and do npm install , the folder is

Accessing node_modules after npm install inside Docker

﹥>﹥吖頭↗ 提交于 2019-12-06 08:58:04
问题 I am running Docker with Docker Machine on Mac. I successfully set up some containers and ran npm install inside them, as explained here. This installs the node_modules inside the image and inside the container, but they are not available on the host, i.e. my IDE complains about missing node_modules. Am I missing something? What is the best way to run npm install inside the container but be able to do development (with these dependencies) on the host? From my docker-compose.yml: volumes: -

Use @types definitions in project .d.ts definition file

余生长醉 提交于 2019-12-06 07:37:24
I'm trying to write a .d.ts file for my project to define some global interfaces. However I have a problem using non-global library types inside that definition file. Especially RxJs which I'm trying to reference does not work for me. The thing I thought would work the best was using a triple-slash reference tag to import the types for RxJs, however this didn't work. /// <reference types="rxjs" /> interface IUserService { user$: rxjs.Observable<IUser>; } I found the solution to what I wanted to do: import RxJs from 'rxjs'; declare global { interface IUserService { user$: RxJs.Observable<IUser>

autocompile .coffee files and reload project

家住魔仙堡 提交于 2019-12-06 07:17:39
I have a small web service developed in node, and I'd like to code some files in coffeescript, to start playing with it. I'm using nodemon to run the app, like this nodemon app.js And I have the following file structure app.js controllers/ ping.coffee test.js In nodemon's homepage it says that it supports coffeescript, but I change the file and it won't get reloaded. Then I found this article , so I tried with $ coffee --watch --compile ./controllers/*.coffee And it works fine, but if I try with $ coffee --watch --compile ./*.coffee File not found: ./*.coffee So it seems like the watch option

how does createConnection work with nodeJS in mysql?

徘徊边缘 提交于 2019-12-06 04:37:07
问题 What does createConnection do? var connection = mysql.createConnection({ host : 'example.org', user : 'bob', password : 'secret' }); I'm writing an application in nodeJS using mysql module. I have some own modules, for example authentication , which definetely needs DB connection. Question is: if I have multiple modules where I use this method to create the connection, will it create a new connection for me everytime or use the first one? If creates, it creates the first time it loads my own

typescript module resolution

天大地大妈咪最大 提交于 2019-12-06 00:59:33
问题 Is there a typescript module resolution strategy that would allow me to have both local imports not starting with a slash and imports from node_modules in the same module? With "moduleResolution" set to "node" the compiler cannot find my local modules, with all other options it does not see the modules in node_modules directory I'm trying to import. I have the following imports in my file: import {Injectable} from "angular2/core"; import {Logger} from "core/logging/Logger"; "angular2/core" is