0.1.0 • Published 6 months ago
demo-hello-npm-package v0.1.0
Demo Hello NPM Package
This is a simple NPM package that serves as an example.
Installation
You can install this package using npm:
npm install demo-hello-npm-package
Usage
First, create a new TypeScript project and initialize it with a tsconfig.json
file:
mkdir my-ts-project
cd my-ts-project
npm init -y
npm install typescript --save-dev
npx tsc --init
Next, update the package.json
file with the following:
{
"main": "dist/index.js",
"type": "module",
...
}
Next, update the tsconfig.json
file to the following:
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "node",
"target": "ESNext",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"outDir": "./dist",
"rootDir": "./src"
}
}
Next, install the package:
npm install demo-hello-npm-package
Create a src
directory and add an index.ts
file:
mkdir src
echo 'import { helloNpm } from "demo-hello-npm-package";
const hello = helloNpm();
console.log(hello);' > src/index.ts
Compile the TypeScript files:
npx tsc
Run the compiled JavaScript file from the dist
directory:
node dist/index.js
This will print "Hello, world!" to the console.
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
License
This project is licensed under the ISC License