Is it possible to host a website on the same project as an npm package?

So, I’m making a package, and it would be nice if I didn’t have to have a separate project for the website/docs etc. (I’d rather not do it in a README) so I don’t have to continually switch projects whenever I make a change. I could do the routing with express - but would the server.js file then be the code published for the package if I put it as the start script?
Sorry if that didn’t make any sense :smiley:
Thanks in advance for any help!

Yes, that should be published, too.

So if that’s the case would people end up running the server file when they tried to use the package?

Sorry but I do know about this.

This is possible but not on Glitch. Probably on GitHub using GitHub Pages it’ll work as you expect it to. For example, jsoning has the all the package code and the documentation (in a folder named docs) in the same repo. GitHub Pages has an option to serve files from a specific folder in a repo, so I set the docs folder to be served as a GitHub Pages website.

1 Like

:eyes:

What I do is have subdirectories in /app. I have an /app/server directory with the stuff for Glitch to run and an /app/client directory with an npm package. Then at the top level, I have an /app/package.json with a “start” script that cd’s into server and runs it from there.

You can see the directory structure here https://glitch.com/edit/#!/daffy-circular-chartreuse but you can’t see the top level package.json. (I put it in .gitignore because it’s a weird Glitch-specific thing that I’m choosing not to include in my repo.) It has this content in /app/package.json:

{
        "scripts": {
                "install": "cd server && npm install --no-optional",
                "start": "cd server && node server.js"
        }
}

Thanks a lot! That’s very useful.

@wh0 Hang on - let me just check here - am I correct in saying:
You don’t need to point to the client at all? You just point to the server so it works and then npm assumes that your package’s code is in client?

If so, why does this work?

Or when you publish it do you need to specify which directory to publish from?

I am officially even more confused than I was before :D

I don’t run the client on that Glitch project. I only run the server on that Glitch project.

Would you be running a docs site that uses the npm package too?