https://github.com/mohammedhrima/test-server
how to publish a package in npm
https://github.com/mohammedhrima/test-server
Last synced: about 1 month ago
JSON representation
how to publish a package in npm
- Host: GitHub
- URL: https://github.com/mohammedhrima/test-server
- Owner: mohammedhrima
- Created: 2024-12-09T07:44:21.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-12-09T08:19:07.000Z (6 months ago)
- Last Synced: 2025-05-06T18:17:59.614Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 1.95 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# how to publish a npm package
```bash
npm init -y
``````json
{
"name": "test-server",
"version": "1.0.0",
"description": "A simple web server",
"main": "server.js",
"bin": {
"test-server": "server.js"
},
"dependencies": {
"express": "^4.21.2"
}
}
``````bash
npm install express
touch server.js
``````js // server.js
#!/usr/bin/env nodeconst express = require("express");
const { program } = require("commander");program.option("-p, --port ", "Port to run the server", "3000").parse(process.argv);
const options = program.opts();
const app = express();
const port = parseInt(options.port, 10);app.get("/", (req, res) => {
res.send("Hello from Hrima Server!");
});app.listen(port, () => {
console.log(`Hrima Server is running at http://localhost:${port}`);
});```
```bash
chmod +x server.js
npm link
test-server
``````bash
npm login
npm publish
``````bash
npm install -g test-server
test-server
``````bash
npm uninstall -g test-server
```