TypeScript definition for builtin 'net' NodeJS types? - node.js

I am trying to write a TCP client application, and for that the builtin 'net' package seems to do the job. However, I am not able to find the TypeScript definitions for the package.
https://nodejs.org/api/net.html
Since it is built into NodeJs, I am almost sure it exists, but it cannot find any information about it anywhere.
Thanks!

They are available in the official typings for node. Install it with npm install #types/node --save-dev and you can import it in your TypeScript code using: import * as net from "net";

Related

hapi.js Version 18.x Typings

I recently upgraded my project to use the #hapi/hapi node modules vs. the old hapi module. I'm using version 18.3.1 ("#hapi/hapi": "^18.3.1").
My Typescript definitions no longer work as the Import reads: import * as Hapi from 'hapi';
When running the node process I get the module not found error. Is there a way to point the #types/hapi typings to the new #hapi/hapi module?
Uninstall the #types/hapi dependency. This didn't work for me moving to 18.3.1. Instead install #types/hapi__hapi. I searched for a while and ran across that package, which seems to do the trick.
npm un #types/hapi -D
npm i #types/hapi__hapi -D
Then instead of importing from 'hapi', import from '#hapi/hapi'.
import * as Hapi from '#hapi/hapi';

Can I use browserify to transpile into a NPM module that can be imported into another project?

Is it possible for me to use browserify to transpile my ES6 code into one distribution published to NPM?
Here is what I'm doing. I am trying to create a NPM module that will be used in many of my projects. The NPM module I have is something derived from an already existing project using grunt-browserify+babelify. The problem I'm running into is when I import the NPM module into another project and run browserify on it, I'm getting an
>> Error: Cannot find module './foo/bar' from '/Users/joeuser/working/project123/node_modules/my-npm-module/lib'
Is what I'm trying even possible?

how to use #types/node in node application

I am working in VSCode on Ubuntu 16.04. I've created node project using below commads:
npm init
tsc --init
I've created a new file called index.ts. I'm trying to use fs and readling to read file contents. but when I am writing below lines of code at the top of index.d.ts:
import fs = require('fs');
import readline = require('readline');
I'm getting below error:
can not find module 'fs' and can not find module 'readline'
even process is not found.
I've installed typings of node from here using below command:
sudo npm install #types/node -global --save
Can anyone please help me how to resolve this error?
Since TypeScript 2.x, all typings are installed using npm like this: npm install #types/node.
For TypeScript 1.8, it might be better to typings to install the node types. For detail see the quickstart at: https://basarat.gitbooks.io/typescript/content/docs/quick/nodejs.html.
For what i know you have two options here:
(Recommended) Install devDepencencie npm install #types/node --save-dev, which will add the type module for http.
Create a index.d.ts file declaring a definition for http module, like:
declare module 'http. This method will not enable auto-complete for http methods

when was require("which") born?

Just noticed I can use a module called which in nodejs 6.x. require("which"). But cannot find docs to this native module. Can some one tell where the docs are and at which version of node the module was introduced?
which is not a built-in module even in Node 6.3.0.
Presumably you have installed it from npm using the -g flag to install it globally.

Where do I install a package with npm in Meteor 1.3 so that other npm libraries can require it

I’m trying to get set up with cloudinary in Meteor 1.3 beta, and I’m going for an NPM package right now. I’ve run in to a larger problem where in one of the package libraries there is a declaration crypto = require('crypto'); Which is fine. I just installed the crypto package through npm. But the client is still giving me the error Uncaught Error: Cannot find module 'crypto' . … any suggestions?
Note, both modules are in the same node_modules directory:
node_modules
crypto
material-ui
react
react-cloudinary
react-dom
react-mounter
react-tap-event-plugin
This is particularly a Meteor 1.3 issue since I’m importing npm libraries
If module A requires module B than module B needs to be available in the node_modules directory of module A. That's the usual thing that npm and node do and that you're probably familiar with. It works the same way in meteor 1.3.
If you are the developer of module A than you can look at peer dependencies in npm or npm link. Or you just run npm install in the module and see if that fixes the problem.
The NPM package crypto can only be used on the server side because it's a built-in library of NodeJS. It's a high-performance library so perhaps it's compiled.
If you can change the code you could instead use a pure js library for creating hashes such as JS Hashes.
JS Hashes can be used on the client-side as well as the server-side.

Resources