How to customize APIs locally

I’ve created a new endpoint locally in the project. But each time I build the docker image and run locally the new code I’ve written doesn’t appear. For example, I’ve tried to add a console.log statement to the existing /rest/node-types endpoint and the log is never outputted.

I added a log statement in the following endpoint in Server.ts but the log is never outputted:

	// Returns all the node-types
	this.app.get('/rest/node-types', ResponseHelper.send(async (req: express.Request, res: express.Response): Promise<INodeTypeDescription[]> => {

		console.log('All node types returned');

		const returnData: INodeTypeDescription[] = [];
		const nodeTypes = NodeTypes();
		const allNodes = nodeTypes.getAll();

		allNodes.forEach((nodeData) => {
			returnData.push(nodeData.description);
		});

		return {};
	}));

Any ideas?

I’m running with the following commands to start the server locally.

> docker build --build-arg N8N_VERSION=0.36.1 -t XXXX .
> docker run -p 5678:5678 XYZ

Ah yes sorry but you can change whatever you want locally it will never make it in the docker image. You can check the Dockerfile here: https://github.com/n8n-io/n8n/blob/master/docker/images/n8n/Dockerfile

You will see that it gets the n8n code from npm and so has nothing to do with the files you have locally at all. You would have to create totally different Dockerfile.
The Dockerfile you need would have to copy in your local code and then run npm install in the container. If you only want to make changes to n8n-cli it should be quite simple. If you also want to make changes to the other modules it would get more complicated as you would then have to have the lerna-setup in the docker container.

But one question. What do you want to do exactly? Like do you want to develop for n8n or do you want to make changes and then really run it like that long term?

Just looking to host a slightly modified version of n8n on my own server for a personal project.

I tried creating the following Dockerfile but am getting errors:

FROM node:10
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 5678
CMD npm start

Each time this outputs the following:

> [email protected] start /usr/src/app
> run-script-os
> [email protected] start:default /usr/src/app
> cd bin && ./n8n
 › Error: command start not found
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] start:default: `cd bin && ./n8n`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the [email protected] start:default script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2019-11-25T00_45_14_196Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] start: `run-script-os`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

How can this be fixed? Thanks!

But where are the modifications? Only in n8n-cli or also in other packages?

For now just in the n8n-cli. Eventually I might make some modifications to the web client. Can you suggest how to make the dockerfile work so I can run the n8n-cli locally? Thank you.

If you just want to make changes to the CLI you can for now use this Dockerfile:

FROM node:10
WORKDIR /usr/src/app
COPY . .
RUN rm -rf node_modules
RUN npm install && npm run build
EXPOSE 5678
CMD npm start

Make sure that you pull the latest code from GitHub else you will have problems with the build part.