npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nodeployed

v1.5.4

Published

Package that deploys code to server on each repository push via Webhooks

Downloads

76

Readme

NPM version License All Contributors

Another deployer?!

I wanted to make easily the process of deploying code to server on each push to repository. I tried almost all suggested ways to do it but they didn't work. So I created this package. It supports Ubuntu servers and GitHub/GitLab/Bitbucket repos.

Uses

Nodeployed uses Fastify as Node.js server, Execa to run such commands to deploy code and Minimist to parse command arguments.

Server preparation

To be able to use it sucessfully, you need:

  • Install Node.js and npm on your server
  • Setup your Apache/NGINX server to reverse proxy all requests to http://localhost:YOUR_PORT in location block:

  • For NGINX change your server block config to something like this:

# Your server in /etc/nginx/sites-available/example.com
server {
...
    location /deploy/ {
        proxy_pass http://localhost:YOUR_PORT;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
...
}
  • For Apache2:
<VirtualHost *:*>
    ProxyPass /deploy/ http://0.0.0.0:3000/
    ServerName localhost
</VirtualHost>
  • Optionally: Install LetsEncrypt on that domain that you will use.
  • Clone repository that you want to work with with git clone
  • Run sudo chown -R yourusername:webserverusername you-repo-dir-name/ for your repository directory to make script able to fully use git commands.

Usage

Install package globally from NPM repo via npm and start the process with pm2:

$ npm i -g nodeployed pm2
$ pm2 start nodeployed -- --port 8234 --dir /absolute/path/to/git/dir/ --command "command1_to_run && command2_to_run ..."

Go to http://example.com/deploy. If script is properly working then you should see this message:

Nodeployed is working! You should set this link in your Webhooks configuration for your repository!

We will configure our repository later in Configure repository for nodeployed section.

Also if you want to run nodeployed as system service pm2 can help you. For that run next commands:

$ pm2 startup systemd

And then copy the command from the output and run it, example:

$ sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u user --hp /home/user

You can save current configuration of running applications if you run multiple instances of nodeployed:

$ pm2 save

Then you can see the status of pm2 system service by running:

$ systemctl status pm2-user

or start it:

$ sudo systemctl start pm2-user

or stop it by running next command:

$ sudo systemctl stop pm2-user

where user – username that gave you pm2 from running the pm2 startup systemd command.

Configure repository for nodeployed

GitHub:

  1. Go to the directory for which you would like to setup autodeploy to your server.
  2. Go to Settings page.
  3. Go to Webhooks page => Add webhook.
  4. Type in your GitHub password if prompted
  5. Setup webhook:
  • Payload: http://example.com/deploy/?token=YOUR_TOKEN_FROM_ARGUMENT
  • Content Type: application/json
  • Which events would you like to trigger this webhook? Just the push event.
  • Active: check it
  • Press Add webhook
  1. Now on any push to this GitHub repository nodeployed should pull changes on server and run deploy commands.

GitLab:

  1. Go to the directory for which you would like to setup autodeploy to your server.
  2. Go to Settings => Integrations.
  3. Setup webhook:
  • URL: http://example.com/deploy/?token=YOUR_TOKEN_FROM_ARGUMENT
  • Secret Token: leave it empty
  • Trigger events: Push events
  • Enable SSL verification: check it if you have installed LetsEncrypt
  • Press Add webhook
  1. Now on any push to this GitLab repository nodeployed should pull changes on server and run deploy commands.

Bitbucket:

  1. Go to the directory for which you would like to setup autodeploy to your server.
  2. Go to Settings => Webhooks => Add webhook.
  3. Setup webhook:
  • Title: any value, e.g. nodeployed to recognize it
  • URL: http://example.com/deploy/?token=YOUR_TOKEN_FROM_ARGUMENT
  • Skip certificate verification: check it if you haven't installed LetsEncrypt
  • Enable request history collection: check it
  • Triggers: Repository push
  • Press Save
  1. Now on any push to this Bitbucket repository nodeployed should pull changes on server and run deploy commands.

Options

--port [PORT]

Default: 9000
Maximum: 65535
Type: number

Sets IPv4 port on which server will be running and listening for requests.

--token [TOKEN]

Type: string:required

Sets the token to validate server request.

--dir [DIR_PATH]

Type: string:required

Sets the absoulte path to target deploy GIT repository.

--command [COMMANDS]

Default: bash ./deploy.sh
Type: string

Pass commands that needs to run after pull from repository/to deploy, e.g. --command "npm install && npm run build". If nothing passed to --command it will fallback to command bash ./deploy.sh so you need to manually create this script with all needed commands.

--branch [BRANCH_NAME]

Default: master
Type: string

Sets the working branch for target deploy GIT repository.

LICENSE

MIT

Contributors

Thanks goes to these wonderful people (emoji key):

| Paul Ekshmidt💻 📖 🚧 🤔 | | :---: |

This project follows the all-contributors specification. Contributions of any kind welcome!